当 rest api 应用程序服务器(express)和 Angulars js 应用程序在不同的端口上运行时,Cors
Cors issue when rest api application server(express) and Angulars js application running on different port
我有用node编写的rest api应用程序.js和express在同一服务器上的端口3000上运行,angularjs应用程序在同一服务器上的端口9001上运行。在从 angularjs 应用程序调用 rst api 时,它给出了 cors 问题。
在 rest api 应用程序中,我使用了"cors"模块
var cors = require('cors');
app.use(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.options('*', cors((( 来解决它;就在所有路由之前。
这是一个带有http-request-header"OPTIONS"的预检请求问题
您可以将解决方案设置为
app.configure('development', function(){
app.set('origins', '*:*');
}
相关文章:
- Canvas Html5绘图应用程序,移动画布会导致重大问题
- Emberjs应用程序加载在除Index之外的所有路由上
- 使用电话间隙在Android应用程序中显示SQL Lite的数据
- 在AngularJS应用程序中使用封装指令和路由的推荐方式是什么
- Windows8应用程序(html&Javascript):从图片库(除了文件选择器)显示图像的另一种方式
- AngularJS应用程序中的CORS错误
- 在不同端口上运行时,rest api应用程序服务器(express)和Angulars js应用程序之间的Cors问题
- 访问 WebGL 的 Soundcloud 波形/插图 (三.js) 应用程序 - CORS 问题
- 当 rest api 应用程序服务器(express)和 Angulars js 应用程序在不同的端口上运行时,Cors
- 在phonegap应用程序的node.js服务器上使用CORS
- 从文件//scheme运行的应用程序出现CORS错误
- CORS标头在MEAN堆栈应用程序中不工作
- 由于CORS错误,无法跨域ajax发布到Heroku上的Rails应用程序
- 可扩展应用程序的CORS问题
- 你好,我需要知道如何在OpenShift的RAILS REST应用程序中启用CORS
- 如何在Phonegap应用程序中使用canvas来启用CORS
- CORS问题在顶点应用程序不工作
- 无法绕过angularjs种子应用程序中的CORS
- 使用.getJSON获取Play Store应用程序详细信息时,获取跨来源块请求[CORS]错误
- Netbeans 8.0.2 中 Cordova 应用程序的 CORS 问题