We are using browsersync in development. For a payment confirmation, the payment provider posts back to a predefined url.
The problem is, that Browsersync only displays Cannot POST /payment/success.
So I was thinking about writing a middleware that takes the POST request and redirects to the same URL as a GET request. The problem is, I'm not sure if this is possible with browser sync. When I try to call res.redirect('/') it throws an error:
browserSync.init
server:
baseDir: "...."
index: "/statics/master.html"
middleware: [
modRewrite(['!\\.\\w+$ /statics/master.html [L]']),
(req, res, next) ->
res.redirect('/') # this throws a TypeError: res.redirect is not a function
]
- Why is
res.redirectnot defined? I thought browser sync is based on express?- How could I access the body of the post request?
req.bodyreturnsundefined
browserSync uses Connect for the middleware and doesn't share the same api as Express it seems.
For a redirect you can at least do the following:
res.writeHead(301, {Location: url});
res.end();
Have a look at their documentation for accessing the request body. The section in Middleware regarding body parsing may yield some results for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With