如何添加“res.addHeader(QUOT;访问控制允许来源"," * QUOT;)”中的前preSS JS? [英] How to add 'res.addHeader("Access-Control-Allow-Origin", "*")' in express js?
问题描述
在我的应用我使用angularjs和科尔多瓦的前端和前preSS和后端其中充当服务器节点的js。我的客户端是在运行的http://本地主机:9000 但是,我的前preSS JS是在<运行HREF =HTTP://本地主机:3000相对=nofollow> HTTP://本地主机:3000 。我需要从EX preSS API获取数据。当访问,上面写着
In my app I use angularjs and cordova for front-end and express and node js for backend which is acting as server. My client side is running on http://localhost:9000 but, my express js is running on http://localhost:3000. I need to get data from express API. While accessing, it says '
XMLHttpRequest cannot load http://localhost:3000/data. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access.
对于这一点,我需要添加 res.addHeader(访问控制允许来源,*)
。这是从其他域访问一个域。如何添加在EX preSS JS这个头?请帮我..
For this, i need to add res.addHeader("Access-Control-Allow-Origin", "*")
. It is to access one domain from other domain. How to add this header in express js? Please, help me out..
推荐答案
我也开始学习这件事,同时寻找,我发现与此相关的。
I'm also started learning about this and while searching I found related to this.
访问控制允许来源只接受*或单一起源。
Access-Control-Allow-Origin only accepts * or a single origin.
如果你想支持多种来源,但不是所有的人,那么你必须:
If you want to support multiple origins but not all of them, then you must:
看产地请求头
检查它是否是你可以接受的起源名单
把它放在访问控制允许来源响应头
look at the Origin request header check if it is on your list of acceptable origins put it in the Access-Control-Allow-Origin response header
请参阅本如果能对您有所帮助。
See this if it could be helpful to you.
<一个href=\"http://stackoverflow.com/questions/18310394/no-access-control-allow-origin-node-apache-port-issue\">No 访问控制允许来源 - 节点/ Apache的端口号
这篇关于如何添加“res.addHeader(QUOT;访问控制允许来源&QUOT;,&QUOT; * QUOT;)”中的前preSS JS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!