I am using webpack-dev-server as a proxy to my original API URL to avoid CORS related issues and dynamically pointing to Dev, UAT, Mock server URL based on the environments.
For Mock dev - I prefer to use the JSON from the local file system and it servers its purpose for all the GET request.
How to to add support for 'POST, PUT, DELETE' so that the local JSON can be served directly?
One possible approach may be - Overriding the HTTP Request methods to GET as I am not passing any payload. But I can't find any configuration for that.
Below is the current configuration :
if (IS_MOCK_SERVER) {
devServer.proxy = {
'/api': {
target: 'http://localhost:9090/data',
secure: false,
pathRewrite: function(req, options) {
return req + '.json'
}
}
}
} else {
devServer.proxy = {
'/api': {
target: 'http://dev-server-url.com',
secure: false
}
}
}
I tried digging into the official documents, but didn't get much support on this topic.
The Webpack dev server makes use of http-proxy-middleware to optionally proxy requests to a separate, possibly external, backend server.