我正在使用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
任何解决此问题的建议?非常感谢。
sockPort: 'location'
,这样套接字端口将使用与位置端口相同的端口,通常足够了。 - Cyrille Pontvieuxheaders: ...
下,添加allowedHosts: ["localhost", ".host.com", "host2.com", "subdomain.host3.com"]
。.host.com
条目是该域上任何子域的通配符。您还可以使用"auto"
,有关详细信息,请参阅 此处。 - ryanjdillon