我想将/ v1 / *代理到http://myserver.com,这是我的脚本
devServer: {
historyApiFallBack: true,
// progress: true,
hot: true,
inline: true,
// https: true,
port: 8081,
contentBase: path.resolve(__dirname, 'public'),
proxy: {
'/v1/*': {
target: 'http://api.in.uprintf.com',
secure: false
// changeOrigin: true
}
}
},
但这不起作用
最佳答案
更新:
感谢@chimurai,设置changeOrigin: true
对于使其工作很重要。
Underneath webpack-dev-server
将所有代理配置从documentation传递到http-proxy-middleware
。很明显,您想要的用例实际上是通过/v1/**
路径实现的:
devServer: {
historyApiFallBack: true,
// progress: true,
hot: true,
inline: true,
// https: true,
port: 8081,
contentBase: path.resolve(__dirname, 'public'),
proxy: {
'/v1/**': {
target: 'http://api.in.uprintf.com',
secure: false,
changeOrigin: true
}
}
},
关于webpack - webpack-dev-server代理无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36662065/