Skip to content Skip to sidebar Skip to footer

Forward Express Js Route To Other Server

I'm writing an express.js app and would like to serve certain routes from another server. Express serves some routes starting with api.example.com/v1/*. I would like any paths star

Solution 1:

You can use express-http-proxy.

And yes, proxying is the accurate term for what you are looking for. It will underneath forward the request to another url, as the API will also imply.

Here's an example usage:

var proxy = require('express-http-proxy');
var app = require('express')();

app.use('/route/you/want/proxied', proxy('proxyHostHere', {
    forwardPath: function (req, res) {
      return '/path/where/you/want/to/proxy/' + req.url
    }
}))

Post a Comment for "Forward Express Js Route To Other Server"