Webpack-dev-server with bypass proxy

CoderTR picture CoderTR · Nov 6, 2014 · Viewed 22.3k times · Source

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

Martin Grůber picture Martin Grůber · Jun 12, 2015

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

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