使用Node表达后端的ember

时间:2014-05-13 15:46:52

标签: node.js ember.js express

获取“尝试从我的ember应用程序访问节点快速Web服务时,请求的资源上存在'Access-Control-Allow-Origin'标头。

我有一个在http://localhost:3000

上运行的节点Web服务项目

我的ember应用程序项目在http://localhost:63342

上运行

当我尝试连接到我的服务器并请求客户(http://localhost:3000/customers)时,我得到:

XMLHttpRequest cannot load http://localhost:3000/customers. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not allowed access. 

我认为我需要在其余的适配器上做一些事情来允许这个吗?或者是否有办法让两个项目都在同一个端口监听?哪种方式最好?

1 个答案:

答案 0 :(得分:0)

一个非常老的问题。但是以防万一有人还在寻找答案。

您将需要在服务器端(而不是客户端)上配置CORS。我知道的最简单的方法是使用npm软件包cors

npm install cors --save

,然后将其添加为快速应用程序中的中间件

const cors = require('cors');
const express = require('express');
const app = express();
app.use(cors());

检查npm页面,以获取有关如何根据您的特定需求配置cors的更多信息。

相关问题