我希望允许跨域调用,这样我就可以执行对服务器的rest 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种子应用作为我的应用基础。