ggondim / docker-node-http-proxy

A simple HTTP proxy running in Node.js within a Docker container.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

docker-node-http-proxy

A simple HTTP proxy running in Node.js within a Docker container.

Usage

Set your proxies in proxies.json

[
  {
    "target": "https://google.com",
    "changeOrigin": true,
    "pathFilter": "/google**",
    "followRedirects": true,
    "prependPath": true,
    "ignorePath": true
  }
]

See all the supported options in http-proxy-middleware.

Run the container

$ npm run docker:run

Requests now are proxied in the HTTP 80 port

$ curl -i http://localhost/google

Customizing

You can use http-proxy-middleware's advanced options creating more middlewares in index.js:

// ## ADD YOUR CUSTOM PROXIES HERE ##
app.use(
  '/api',
  createProxyMiddleware({
    target: 'http://www.example.org/api',
    changeOrigin: true,
    pathFilter: '/api/proxy-only-this-path',
    pathRewrite: function (path, req) { return path.replace('/api', '/base/api') }
  })
);

Testing outside the container

$ npm run dev

About

A simple HTTP proxy running in Node.js within a Docker container.

License:MIT License


Languages

Language:JavaScript 81.8%Language:Dockerfile 18.2%