express.io
express.io copied to clipboard
Access-Control-Allow-Origin
How can I avoid "No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access." when I try to connect from a webpage which is local on my computer.
XMLHttpRequest cannot load http://XXXXXX.fr/socket.io/1/?t=1424435597528. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
I'm using the cors module for express routing.
var express = require('express.io');
app = express();
var cors = require('cors');
app.use(cors());
app.http().io();
app.listen(8080);
This works for express, but I wasn't able to find a good answer to the exact issue you are asking about. Other than to serve socket.io.js from the same location I was trying to connect. My client side application header.
<script src="http://localhost:8080/socket.io/socket.io.js"></script>
And that has resolved the issue. I think a better solution would be having the cors module handle socket.io.