我想允许访问我需要能够对服务器执行其余 API 调用的跨源调用。
我的 connect grunt 任务配置如下:
connect: {
options: {
port: 9000,
// Change this to '0.0.0.0' to access the server from outside.
hostname: 'localhost',
livereload: 35729,
middleware: function(connect, options, next) {
return [
function(req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
next();
}
];
}
},
},
当我运行 grunt 服务器时,我得到了Cannot GET /
. 如果没有中间件配置,应用程序正在工作并且索引文件已正确加载。
你能指导我做错了什么或错过了什么吗?
关于我的 gruntfile 的更多细节是我正在使用 yeoman angular seed 应用程序作为我的应用程序的基础。