【发布时间】:2015-10-14 15:56:03
【问题描述】:
我正在使用webpack-dev-server v1.10.1 来提升我的 Redux 项目,我有以下选项:
contentBase: `http://${config.HOST}:${config.PORT}`,
quiet: false,
noInfo: true,
hot: true,
inline: true,
lazy: false,
publicPath: configWebpack.output.publicPath,
headers: {"Access-Control-Allow-Origin": "*"},
stats: {colors: true}
在 JS 中,我使用来自 superagent 的 request 来生成 HTTP GET 调用
request
.get(config.APIHost + apiUrl)
.set('Accept', 'application/json')
.withCredentials()
.end(function (err, res) {
if (!err && res.body) {
disptach(() => {
return {
type: actionType || GET_DATA,
payload: {
response: res.body
}
}
});
}
});
但我收到了 CORS 错误:
XMLHttpRequest cannot load http://localhost:8000/api/getContentByType?category=all. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:5050' is therefore not allowed access
有解决此问题的建议吗?非常感谢
【问题讨论】:
标签: reactjs webpack cors webpack-dev-server superagent