dan*_*oon 1 http-proxy webpack-dev-server
有没有办法只允许使用 Webpack Dev Server 代理 POST 请求?我的应用程序将 /login 用于 GET 请求,不幸的是,无论 HTTP 方法如何,它都被代理到我的其他主机。
// Serve the Relay app
const compiler = webpack(config);
appServer = new WebpackDevServer(compiler, {
contentBase: '/public/',
proxy: {
'/login': `http://localhost:${GRAPHQL_PORT}`, // only for POST?
},
publicPath: '/js/',
stats: {
colors: true,
chunks: false,
},
historyApiFallback: true
});
Run Code Online (Sandbox Code Playgroud)
就在这里。您可以使用旁路参数。
// Serve the Relay app
const compiler = webpack(config);
appServer = new WebpackDevServer(compiler, {
contentBase: '/public/',
proxy: {
'/login': {
target: `http://localhost:${GRAPHQL_PORT}`, // only for POST?
bypass: function(req, res, proxyOptions) {
if(req.method != 'POST') return false;
}
}
},
publicPath: '/js/',
stats: {
colors: true,
chunks: false,
},
historyApiFallback: true
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3399 次 |
| 最近记录: |