CoderTR CoderTR - 3 months ago 48
Javascript Question

Webpack-dev-server with bypass proxy

How to achieve a 'proxy' (similar to grunt-connect-proxy) option with webpack-dev-server ?

I am using webpack and webpack-dev-server with Grunt. A task in Gruntfile.js (below code) is able to start the server on port 8080. I want to add proxy setup for all the backend data requests (context URL /ajax/*).

"webpack-dev-server": {
options: {
webpack: webpackConfig,
publicPath: "/src/assets"
},
start: {
keepAlive: true,
watch: true
}
}

Answer

In the webpack config, you can use devServer.proxy like this:

proxy: {
    '/ajax/*': 'http://your.backend/'
}