Monday 5 June 2017

Replicate Nginx proxy_pass on NodeJs + Express

If you do this in Nginx:

location /apiproxy/ {
    proxy_pass                      https://apidev.site.com/;
}

All request to domain.com/apiproxy/* will be passed to apidev.site.com/*, so domain.com/apiproxy/foo/bar/ will be passed to apidev.site.com/foo/bar.

Im trying to replicate the same behavior in NodeJS with express and proxy, according to documentation:

app.use('/apiproxy/*', proxy('https://apidev.site.com/v1', {
    proxyReqPathResolver: function(req) {
        console.log(require('url').parse(req.url).path);
        return require('url').parse(req.url).path;
    }}));

But that loose everithing after /apriproxy/. Any idea?



via DomingoSL

No comments:

Post a Comment