add a path prefix to all of your express routes by simply proxying to them
path-prefix-proxy is an express middlewhere which makes it easy to add a prefix
path your existing express app.
The most common use case for this is when you have different services running on different express servers, but you have something like nginx proxying all of these services to a single hostname.
For example, say you have an app that currently has the routes
GET /loginPOST /loginGET /logout
But you've realised you want to share the host with some other services. So you'd
like to prefix all of these paths with
/auth, going to:
GET /auth/loginPOST /auth/loginGET /auth/logout
And what if you need these to be configurable? What if you have static resources
that you want to be nested under
/auth as well?
path-prefix-proxy to the
Just add this middleware to your express app like so:
var pathPrefix = '/auth';app;
and immediately your old routes will begin working in their new locations too!
npm install path-prefix-proxy
So now we have everything under
/auth being proxied to our base routes.
But the base routes are still accessible - so going to
/login will yield identical results. What if we don't want this? PPP gives
you an easy way to do this:
var proxy = '/auth';app;app;
/auth/login would be successful, but
/login would not:
GET /auth/login -> 200GET /login -> 403