config-proxy
A simple library that enables the proxying on HTTP requests based on a simple configuration.
Example using the library:
var Router = var http = var router = var server = httpserver
Example using the CLI tool:
$ sudo npm install -g config-proxy
A file living in /etc/config-proxy.json
:
We run the config-proxy HTTP server pointing at our config file and listening on port 8080:
$ config-proxy --config /etc/config-proxy.json --port 8080
install
$ npm install config-proxy
test
$ npm test
Config
- routes - maps URLs onto backends
- default - which route to use if there is no match
The value of the routes can be in env:VARNAME
format. This means load the value of this environment variable
as the backend route.
routes()
This function will return the processed routes back for analysis:
var routes = router console
URL re-writing
Let's say that you proxy /v1/projects
back to the projects micro-service.
Imaging that this micro-service just hosts '/v1/project/apples' (i.e. without projects
)
This would mean we want the following URL re-writing to happen:
/v1/projects/project/apples
-> /v1/project/apples
This can be done by appending /<route>
after the proxy target in the config:
Licence
MIT