Javascript rest api应用程序服务器(express)和Angulars js应用程序在不同端口上运行时出现Cors问题

Javascript rest api应用程序服务器(express)和Angulars js应用程序在不同端口上运行时出现Cors问题,javascript,angularjs,node.js,rest,Javascript,Angularjs,Node.js,Rest,我在node.js中编写了rest api应用程序&express在同一服务器上的端口3000上运行,angularjs应用程序在端口9001上运行。从angularjs应用程序调用RSTAPI时,会出现cors问题 在RESTAPI应用程序中,我使用了“cors”模块 但它给了我以下的错误 Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://lo

我在node.js中编写了rest api应用程序&express在同一服务器上的端口3000上运行,angularjs应用程序在端口9001上运行。从angularjs应用程序调用RSTAPI时,会出现cors问题

在RESTAPI应用程序中,我使用了“cors”模块

但它给了我以下的错误

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:3000/api/user/login. This can be fixed by moving the resource to the same domain or enabling CORS
请求头和响应头如下所示

响应标题

Content-Length 222
Content-Type application/json; charset=utf-8
Date Tue, 16 Dec 2014 08:40:05 GMT
X-Powered-By Express
视图源

请求头

Accept application/json, text/plain, /
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Authorization null
Content-Length 47
Content-Type application/json;charset=utf-8
Host localhost:3000
Origin http://localhost:9001
Referer http://localhost:9001/
User-Agent Mozilla/5.0 (Windows NT 6.2; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0

谢谢

您可以将解决方案设置为

app.configure('development', function(){
    app.set('origins', '*:*');
}

我通过添加行app.options('*',cors())解决了这个问题就在所有路线之前


这是一个带有http请求标题“选项”的飞行前请求问题。

这没有任何内容,引证?这与文档无关,这是我们为使用此解决方案的所有域启用跨源策略的正常情况。很抱歉,我的错误,我没有在此处正确键入。在我的代码中,它是app.use(cors());
app.configure('development', function(){
    app.set('origins', '*:*');
}