CORS在服务器上可以正常使用,并且可以正常工作。我尝试使用角度HTTPClient将请求发送到服务器的REST API,但收到了CORS错误。如果在服务器上启用了CORS,为什么会出错?对客户来说还可以吗?
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).
为了以后的参考,是“ Davids”的回答为我提供了帮助,没有在所有路由之前添加cors。
“ .....含义,在定义路线之前。” 因此... var app = express();之后
我只是用... app.use(cors());
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句