angular から Express.io ソケットに接続しようとしましたが、エラー 404 CORS が発生しました。どうすればこれを解決できますか?
XMLHttpRequest cannot load http://localhost:3000/socket.io/?EIO=3&transport=polling&t=1447367208172-29. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.
このルートをブラウザから直接ロードするとうまくいきますが、localhost:80 angular から localhot:3000 express.io が機能しません。
Express.io で CORS を無効にしました。通常の ajax リクエストではうまく機能しますが、 socket.io では機能しません。
app.use(function(req, res, next) {
res.header('Access-Control-Allow-Credentials', true);
res.header('Access-Control-Allow-Origin', req.headers.origin);
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept');
next();
});
Express.io での socket.io の初期化:
app.http().io()