您好我正在使用webpack创建一个Web应用程序,这使得REST api调用后端服务器。我遇到的问题是CORS问题,所以我需要使用代理。
这导致我如何将在端口(8080)上运行的wepback-dev-server连接到在端口(7000)上运行的api服务器?我的代理服务器是否与端口(8080)运行相同?
我读了快递,npm node-http-proxy和webpack,但很难将它们捆绑在一起。
我是代理新手。
答案 0 :(得分:2)
在webpack-dev-server的示例配置下方,请参阅代理选项
var config = {
// webpack stuff here ...
//dev server configuration
devServer: {
// ...
// every request made to 'locahost:8080/api/xxxx' will be proxyfied to 'http://localhost:7000/api/xxxx'
proxy: {
"/api/*": {
target: "http://localhost:7000",
secure: false,
rewrite: function(req, options) {
//you can handle rewrite here if you need to
}
},
}
},
//
};
module.exports = config;
如此处所述https://webpack.github.io/docs/webpack-dev-server.html#proxy
希望它有所帮助,
编辑,对于webpack-dev-server v 1.14.1'重写'仍然实施