Http-proxy-middleware: Proxy dont work with post action

Created on 28 Oct 2017  路  7Comments  路  Source: chimurai/http-proxy-middleware

I setup proxy middleware on express. Proxy work as expected with get request. But I can't use login form in anymore.
note: i have rewrite the form action url to my proxy manually.
capture

Setup

  • server: express

proxy middleware configuration

var apiProxy = proxy('/proxy', {
    target: 'https://m.facebook.com/',
    changeOrigin: true,
    pathRewrite: {  '^/proxy/login.php': '/login.php' },
    onProxyReq: (proxyReq, req, res) => {
        proxyReq.setHeader( 'User-Agent', 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)' );
    }
});

server mounting

var app = express();

app.use(apiProxy);
app.listen(3001);

Most helpful comment

POST requests are supported. Some issues might occur if your using body-parser for example. In those cases make sure you've configured/mount the proxy prior to the body-parser.

All 7 comments

Can you reproduce this in an isolated setup?
(without the m.facebook.com as target)

Even better if you can provide a working setup in a repo.

Having the same issue with POST proxys. Give a couple hours and I try to reproduce an example.

Issue has gone stale; Closing issue.
Feel free to re-open.

Thanks.

PS: I think StackOverflow would be a better place to troubleshoot your setup.

@chimurai I've met the same issue and after seeing this ticket, assumed this is a known problem that is going to be addressed. I'm not sure if I can extract a small repro from my project. Are POST requests actually supported by http-proxy-middleware?

POST requests are supported. Some issues might occur if your using body-parser for example. In those cases make sure you've configured/mount the proxy prior to the body-parser.

Thanks, I'm using body-parser indeed, I'll try your suggestion.

FYI - I just tried this - moving above bodyParser... Curious as to why this is necessary?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DylanPiercey picture DylanPiercey  路  6Comments

georgyfarniev picture georgyfarniev  路  7Comments

zh-h picture zh-h  路  3Comments

folterung picture folterung  路  4Comments

pwlerke picture pwlerke  路  6Comments