Sven Buijsrogge Sven Buijsrogge - 1 year ago 237
AngularJS Question

Webpack not accepting POST requests

I'm currently working on an Angular 2 web application which communicates with an API. In the application the user is able to choose a payment option and the API will return the url to the payment service.

The problem is that the payment service uses POST to go to the confirmation page which WebPack does not accept (for some reason it only allows GET requests) and we get the following error:

Cannot POST /selection/payment-method

Does anybody know how we could configure that WebPack allows POST requests also? I've contacted the payment provider but it is not possible to do a GET request instead of POST.


Answer Source

Thanks to @robertklep who send me the link to the proxy documentation we found a way to deal with it. What we needed to do was instead of handling the POST request we needed to transform it someway into a GET. After reading some more of the documentation we came across the setup: property for your webpack-dev-server configuration.

With the setup: property you get the expressjs object and you are able to catch urls before it hits the route that says Cannot POST /url/to/page.

We ended up with this:

devServer: {
    setup: function(app) {'/selection/payment-method', function(req, res) {

This way we got a GET request instead of POST and our application does an API request to check if the payment succeeded or not.

This is only used in development!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download