Skip to content
/ dprox Public

declarative reverse proxy for local development

Notifications You must be signed in to change notification settings

FND/dprox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dprox – declarative reverse proxy for local development

Greenkeeper badge

a simple wrapper around express-http-proxy

Getting Started

ensure Node is available, then install dprox:

$ npm install dprox

create a proxy.config.js:

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 } object (limit 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 to
  • preserveHost: true passes the HTTP Host header through to the respective application
  • preservePrefix: true passes the entry's path (URI prefix) through to the respective application
  • insecure: true skips verification of SSL/TLS certificates
  • requestHeaders: an object of custom headers to add to any incoming request (e.g. { "X-TOKEN": "abc123" }) - these are added to and take precedence over any existing request headers
  • responseHeaders: an object of custom headers to add to any outgoing response (e.g. { "Cache-Control": "max-age=1" }) - these are added to and take precedence over any existing response headers
  • log, if truthy, activates logging for this entry
    • if the value is a function, it will be invoked with the respective HTTP request object (e.g. log: req => { console.log(req.method + req.url); })
    • otherwise the value, unless true, will be prepended to the default log message (e.g. log: "[PROXY]")

middleware functions to serve static files from a corresponding directory or to mock a JSON response might look like this:

    "/assets": require("express").static("static"),
    "/data": (req, res, next) => {
        let data = {
            foo: "hello",
            bar: "world"
        };
        return res.json(data);
    }

Contributing

  • npm install downloads dependencies
  • npm test checks code for stylistic consistency

About

declarative reverse proxy for local development

Resources

Stars

Watchers

Forks

Packages

No packages published