【问题标题】:Ember App Kit CORSEmber 应用套件 CORS
【发布时间】:2014-03-24 21:27:19
【问题描述】:

我正在使用 Ember App Kit 尝试构建一个登录到现有服务器的应用程序。 我的问题是我收到以下消息:

XMLHttpRequest cannot load https://example.server.com/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access. 

我已经在 Google 上搜索过了,似乎我需要在我的 express-server 中添加/启用 CORS。 我尝试了以下各种示例,例如:

  1. https://www.npmjs.org/package/cors
  2. https://github.com/troygoode/node-cors
  3. http://bannockburn.io/2013/09/cross-origin-resource-sharing-cors-with-a-node-js-express-js-and-sencha-touch-app/

但我无法让它运行。

简而言之,我正在尝试查找如何将 CORS 添加到我的 express-server 的示例

干杯,

医生

【问题讨论】:

  • 您是否允许 jQuery 进行跨域 ajax 调用。 $.ajaxSetup({crossDomain: true});

标签: ember.js express cors


【解决方案1】:

把它贴在你的 Em.Application.extend 中,在 ready 钩子里面

$(document).ajaxSend(function (event, xhr, settings) {
  settings.xhrFields = {
    withCredentials: true
  };
});

对于 express,尝试使用 npm 上的 cors 模块。 https://www.npmjs.org/package/cors。它应该开箱即用。

【讨论】:

    【解决方案2】:

    最终我通过使用已经运行的服务器为我的 ember 项目提供服务来躲过一劫。

    感谢 kiwiupover 和 ulisesrmzroche 及时回复

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-19
      • 1970-01-01
      • 2015-05-29
      • 1970-01-01
      相关资源
      最近更新 更多