Answer the question
In order to leave comments, you need to log in
How to set up cors headers in node.js?
client
var socket=io('https://site.com:3000');
socket.on('connect', function (){
code ...
});
var fs = require('fs');
//var cors = require('cors');
var options = {
key: fs.readFileSync('abe5c05b1.key'),
cert: fs.readFileSync('b319649cbd8fb1a80.crt')
};
var http = require('https').createServer(options);
var io = require('socket.io')(http, {
cors: {
origin: 'https://site.com'
}
});
var helper = require('./utils/helper');
http.listen(3000, function(){
console.log('listening on *:3000');
});
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "https://site.com:3000"
Header add Access-Control-Allow-Headers *
Header add Access-Control-Allow-Methods "GET, PUT, POST, DELETE, HEAD, OPTIONS"
</IfModule>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question