devServer.proxy: object

Proxying some URLs can be useful when you have a separate API backend development server and you want to send API requests on the same domain.

The dev-server makes use of the powerful http-proxy-middleware package.

With a backend on localhost:3000, you can use this to enable proxying:

1
2
3
proxy: {
'/api': 'http://localhost:3000'
}

A request to /api/users will now proxy to the request to http://localhost:3000/api/users

If you don’t want /api to be passed along, we need to rewrite the path

1
2
3
4
5
6
7
8
proxy: {
'/api': {
target: 'http://localhost:3000',
pathRewrite: {
'^/api': '',
}
}
}

A backend server running on HTTPS with an invalid certificate will not be accepted by default. If you want to, modify config like this:

1
2
3
4
5
6
proxy: {
'/api': {
target: 'https://other-server.example.com',
secure: false,
}
}