declarative reverse proxy for local development
npm install dproxdprox – declarative reverse proxy for local development
=======================================================

a simple wrapper around
express-http-proxy
Getting Started
---------------
ensure Node is available, then install dprox:
```
$ npm install dprox
create a proxy.config.js:
`javascript`
module.exports = {
self: "localhost:8080",
"/foo": {
uri: "localhost:8081",
preserveHost: true,
preservePrefix: true
},
"/bar": {
uri: "localhost:8082",
preserveHost: true
},
"/assets": "localhost:3000"
};
dprox starts the proxy, reading configuration from proxy.config.js within
the current working directory
dprox -c /path/to/any.js reads a custom configuration file instead
(note that this assumes the dprox executable resides on your PATH, otherwise
you might have to provide the full path to that file)
Configuration
-------------
proxy.config.js is expected to export an object mapping paths to applications
an optional self entry defines the proxy's own address (which defaults to"localhost:3333") - this is either a string or a { uri, limit } objectlimit
( sets the request body size limit - see
express-http-proxy documentation
for details)
each entry is either a URI string, an
Express middleware function
(see below) or an object with the following options:
* uri is the address to pass requests topreserveHost: true
* passes the HTTP Host header through to the respectivepreservePrefix: true
application
* passes the entry's path (URI prefix) through to theinsecure: true
respective application
* skips verification of SSL/TLS certificatesrequestHeaders
* : an object of custom headers to add to any incoming request{ "X-TOKEN": "abc123" }
(e.g. ) - these are added to and take precedence overresponseHeaders
any existing request headers
* : an object of custom headers to add to any outgoing response{ "Cache-Control": "max-age=1" }
(e.g. ) - these are added to and takelog
precedence over any existing response headers
* , if truthy, activates logging for this entrylog: req => { console.log(req.method + req.url); }
* if the value is a function, it will be invoked with the respective HTTP
request object (e.g. )true
* otherwise the value, unless , will be prepended to the default loglog: "[PROXY]"
message (e.g. )
middleware functions to
serve static files from a
corresponding directory or to mock a JSON response might look like this:
`javascript`
"/assets": require("express").static("static"),
"/data": (req, res, next) => {
let data = {
foo: "hello",
bar: "world"
};
return res.json(data);
}
Contributing
------------
* npm install downloads dependenciesnpm test` checks code for stylistic consistency
*