通过 Webpack Dev Server 仅代理 POST 请求(或任何其他 HTTP 方法)?
Proxy only POST requests (or any other HTTP method) through Webpack Dev Server?
有没有办法只允许 POST 请求使用 Webpack Dev Server 进行代理?我的应用程序使用 /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
});
是的,有。您可以使用旁路参数。
// 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
});
有没有办法只允许 POST 请求使用 Webpack Dev Server 进行代理?我的应用程序使用 /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
});
是的,有。您可以使用旁路参数。
// 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
});