javascript - Node.js / Socket.io Access-Control-Allow-Origin error on both local and remote site -
world ! i'm trying json feed client, through node/socket.io server. keep getting, locally, or remotely (using nodejitsu) following error : xmlhttprequest cannot load http://jsonfeed.url. origin http://example.com not allowed access-control-allow-origin.
from research , testing, doesn't depend on browser, on server code. please enlighten me!
server code (i can provide more, tried concise):
var fs = require('fs'), http = require('http'); //use of fs , node-static serve static files client function handler(request, response) { "use strict"; response.writehead(200, { 'content-type': 'text/html', 'access-control-allow-origin' : '*'}); fileserver.serve(request, response); // return correct file } var app = http.createserver(handler), iosocks = require('socket.io').listen(app), staticserv = require('node-static'); // serving files // make files in current folder // accessible web var fileserver = new staticserv.server('./'); app.listen(8080);
that's it, have tried everything... time call geniuses!
ok, how this... first stackoverflow , tried answer, it's bit less cold out there once was, keep going.
then... it's working. not know why, , it's annoying. did removing :
response.writehead(200, { 'content-type': 'text/html', 'access-control-allow-origin' : '*'});
just that. @ beginning when not working!
bonus question, can tell me why??
Comments
Post a Comment