为什么Ember.js不能从我的服务器看到Access-Control-Allow-Origin头? [英] Why isn't Ember.js seeing the Access-Control-Allow-Origin header from my server?

查看:263
本文介绍了为什么Ember.js不能从我的服务器看到Access-Control-Allow-Origin头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序是一个Ember.js前端,在服务器上有一个Go API。我使用FixtureAdapter创建了Ember应用程序。现在我有Go API的后端,我将它转换为RESTAdapter。



当我直接使用浏览器打开我的API,我似乎得到相应的CORS标题:

  Access-Control-Allow-Credentials:true 
Access-Control-Allow-Headers:origin,x-requested -with
访问控制允许方法:PUT,PATCH,GET,POST
访问控制允许原产地:*
访问控制暴露标题:Content-Length $但是,当我的Ember.js应用程序访问API时,我得到 XMLHttpRequest不能加载https://192.168.59.103:8001/notifications。在所请求的资源上没有Access-Control-Allow-Origin头。原因'http://192.168.59.103:9000'因此不允许访问。



我不知道怎么看Ember和AP​​I之间发生了什么。我已阅读此CORS教程,并且在服务器端似乎一切正常。



我包含了 x-requested-with 的位,因为另一个Stack Overflow问题表明jQuery请求需要

解决方案

您的端点也需要使用CORS标头来响应OPTIONS请求 - 这些请求将在实际请求,以确保首先允许请求。


My app is an Ember.js front end with a Go API on the server. I created the Ember app using the FixtureAdapter. Now that I have the Go API back end I converted it to RESTAdapter.

When I hit my API directly with the browser, I seem to get the appropriate CORS headers back:

Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:Origin,x-requested-with
Access-Control-Allow-Methods:PUT,PATCH,GET,POST
Access-Control-Allow-Origin:*
Access-Control-Expose-Headers:Content-Length

However, when my Ember.js app hits the API, I get XMLHttpRequest cannot load https://192.168.59.103:8001/notifications. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://192.168.59.103:9000' is therefore not allowed access..

I don't know how else to see what's going on between Ember and the API. I've read this CORS tutorial and everything seems to be okay on the server end.

I included the bit about x-requested-with because of another Stack Overflow question suggesting that jQuery requests need something different than plain old JavaScript requests.

解决方案

Your endpoints also need to respond with CORS headers to OPTIONS requests- those will execute before the actual request to make sure that the request is allowed first.

这篇关于为什么Ember.js不能从我的服务器看到Access-Control-Allow-Origin头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆