Reputation: 14581
I have a single page app which connects to a back-end REST API on a different server.
On index.html
app load, first thing it does is GET /env.json
which contains the URL for the REST API server. Obviously, it is different in prod than in test than in dev.
Is there any way I can add middleware to the webpack-dev-server so that when it sees GET /env.json
it serves up automatically generated json (based on env var or other)?
If there is an easier way, I am open to it. My assumption was that dev and test would start a backend server and then configure response to GET /env.json
, while prod would have a different file added or dynamically generated.
Upvotes: 0
Views: 438
Reputation: 4738
According to webpack-dev-server source code there is setup
option which takes app
(instance of express) variable as function argument. So, you can manipulate routes by specifying this option in your config:
devServer: {
setup: function(app) {
app.get('env.json', function(req, res) {
// ...
});
}
}
Upvotes: 1