I have a response application that uses react-router
, so using the HTML5 history API, I tried historyApiFallback
set true
to serve 404 paths serving the same index.html
, instead of returning an HTTP response.
This one-page application makes some requests to the remote API server, so I also need to proxy some requests to the explicit server, which I also run during development. The web response application is served on port 3000, and the API on port 3001.
So I tried:
devServer:{ contentBase: 'src/www', //Relative directory for base of server devtool: 'eval', hot: true, //Live-reload inline: true, port: 3000, //Port Number host: 'localhost', //Change to '0.0.0.0' for external facing server historyApiFallback: true, proxy: { '^\/users|sitters|bookings': { target: 'http://127.0.0.1:3001', rewrite: function(req) { req.url = req.url.replace(/^\/api/, ''); } } } }, devtool: 'eval', output: { path: buildPath, //Path of output file filename: 'app.js' },
So, I want the api to be deleted on the remote server if the request path starts with /users
or /sitters
or /bookings
, but otherwise go for historyApiFallback
(serve index.html
).
Of course, currently historyApiFallback always works with an HTML file, but I also need a proxy server to work.
source share