【发布时间】:2018-09-11 17:54:18
【问题描述】:
在使用django-rest-framework 作为后端和reactjs + redux 作为前端的网站上工作。
现在我的后端服务器位于 URL 和端口 http://localhost:8080 上的 vagrant ubuntu 机器上。前端使用 react + redux + webpack(port 80) + cross-fetch 用于 API 请求/响应,服务器在 http://localhost 上。
在使用 cross-fetch 上的 cross-fetch 请求 API 以获取数据时遇到两个错误。
第一个错误:
Failed to load http://localhost/courses-api/all-courses/:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:8000' is therefore not allowed access.
是不是因为端口不同?
第二个错误:
Uncaught (in promise) TypeError: Network request failed
at XMLHttpRequest.xhr.onerror (browser-ponyfill.js:445)
找不到解决问题的方法。两者使用相同的端口会解决我的问题吗?在网上找到解决第一个错误的方法,但不能这样做,因为nodejs 和django 不能使用相同的端口。运行其中一个时,另一个无法在该端口上运行。
【问题讨论】:
标签: node.js redux django-rest-framework fetch redux-thunk