Angular客户端启用CORS [英] Angular client enable CORS
问题描述
CORS在服务器上可以正常使用,并且可以正常工作.我尝试使用角度HTTPClient将请求发送到服务器的REST API,但收到了CORS错误. 如果在服务器上启用了CORS,为什么这是一个错误?对客户来说还可以吗?
CORS is fine on server and works as intended. I tried sending requests to my server's REST API with the angular HTTPClient and I receive a CORS error. Why is this an error if CORS is enabled on the server? Shouldn't it be fine on the client?
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:3000/api/blah/blah (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
如何在此请求上启用CORS......
How can I enable CORS on this request please.....
推荐答案
为了将来起见,是戴维斯"答案为我提供了帮助,在所有布线之前都未添加cors.
For future refrence it was "Davids" answer that assisted me, the cors was not added before all routing.
".....含义,在定义路由之前." 所以...之后 var app = express();
"..... Meaning, before the route is defined." so right after ... var app = express();
我只是用... app.use(cors());
I just use... app.use(cors());
这篇关于Angular客户端启用CORS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!