我有一些通过Express.JS提供的静态页面。设置很容易:
var app = express();
app.configure(function(){
app.use(express.static(path.join(application_root, "StaticPages")));
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
我希望响应包括一个额外的http头(Access-Control-Allow-Origin:*),它应该放在哪里? 我尝试了下面的示例,但是这个头只出现在默认页面上:
app.get('/', function(req, res){
res.setHeader("Access-Control-Allow-Origin", "*");
res.send('Hello World');
});
谢谢。
res.setHeader
未定义的人,请使用res.set
或res.header
。http://expressjs.com/en/api.html#res.set - AndyPerlitch