While working on the web pack dev server (version ^3.9.0), you may have changed some configurations with the proxy configuration, so you can proxy specific paths like /api or /bin to refer to a server of your choice; in this example, we are referencing to our AEM local environment in localhost:4502. While making server calls, the GET HTTP Methods are working as expected and proxying local AEM.
1 2 3 4 5 6 7 8 9 10 | devServer: { port: 9999, inline: true, proxy: [{ context: ['/bin'], target: 'http://localhost:4502', }], writeToDisk, liveReload: !writeToDisk } |
However, the POST HTTP method does not work. You are likely to see a 403 Forbidden error; unable to send data to local AEM (proxy server). A simple solution to fix this is to add append another configuration property to your dev server key named setup(). This will take the original POST URL and redirect with the same URL, making it a GET request; it’s a bit hacky, but it works well.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | devServer: { port: 9999, inline: true, proxy: [{ context: ['/bin'], target: 'http://localhost:4502', }], setup(app) { app.post('*', (req, res) => { res.redirect(req.originalUrl); }); }, writeToDisk, liveReload: !writeToDisk } |
This article should answer your questions for:
- Webpack Dev Server, unable to make a POST to the proxied server?
- Webpack Dev Server, proxy configurations does not allow me to POST?
- Webpack Dev Server, I am getting a 403 Forbidden error whenever I try to make a POST via proxy configurations?
- Webpack Dev Server, Why can’t I make a POST request to my proxy backend server?
- Webpack Dev Server, Why can’t I send data to to my proxied server?
- Webpack Dev Server, 301 forbidden POST request, not able to send data to my server?
- How do I get Webpack Dev Server to accept POST requests