世界 !node/socket.io サーバーを介してクライアントに JSON フィードを取得しようとしています。ローカルまたはリモートで (nodejitsu を使用して) 取得し続けるのは、次のエラーだけです: XMLHttpRequest cannot load http://jsonfeed.url。オリジンhttp://example.comは Access-Control-Allow-Origin で許可されていません。
私の調査とテストによると、それは私のブラウザーではなく、私のサーバー コードに依存しています。教えてください!
サーバーコード(もっと提供できますが、簡潔にしようとしました):
var fs = require('fs'),
http = require('http');
//use of a fs and node-static to serve the static files to client
function handler(request, response) {
"use strict";
response.writeHead(200, {
'Content-Type': 'text/html',
'Access-Control-Allow-Origin' : '*'});
fileServer.serve(request, response); // this will return the correct file
}
var app = http.createServer(handler),
iosocks = require('socket.io').listen(app),
staticserv = require('node-static'); // for serving files
// This will make all the files in the current folder
// accessible from the web
var fileServer = new staticserv.Server('./');
app.listen(8080);
それだけです、私はすべてを試しました... 天才を呼ぶ時が来ました!