私はHerokuでExpressアプリケーションを使用しています。別のNodeJSアプリケーションからRESTfulなリクエストを作成しようとしています。プリフライト要求への応答がアクセス制御チェックに合格しないNodeJS/Heroku/Express
ここでHerokuのアプリからの抜粋だが、app.js
と呼ばれる:
var express= require("express");
app.get("/results",function(req,res){
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.header("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE,OPTIONS");
});
そして、ここでは、私がローカルで実行アプリ、local-app.js
からの抜粋です:
var request= require("superagent");
var req= request.get("http://url-to-app-js.com?query=1").set(
"Access-Control-Allow-Origin", "http://url-to-app-js.com",
"Access-Control-Allow-Methods", "GET,PUT,POST,DELETE,OPTIONS",
"Access-Control-Allow-Headers", "Content-Type, Authorization, Content-Length, X-Requested-With"
);
req.end(function(err,res){
// do things
});
私はlocal-app.js
を実行すると、私はこれを得ましたブラウザのコンソールでエラーが発生しました:esponse to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.
私はブラウザ「Chromium」を特定のセキュリティの設定は無効になっていますが、私はそうすることなくこれを実行できる必要があります。
私は間違っていますか?どうすれば修正できますか?
これはこれまでに実現しましたか? –