Node http transparent proxy with in memory caching for GET calls.
This is mostly for debugging: I use it to cache an unstable system's script responses, so I can keep on working even if the remote server is being restarted (which may last for minutes).
Sometimes I need to work with http only api endpoints, but my local server needs to be https, so to avoid downgrading I can add my own cert. In an ideal world the backend api would return https with the same dev cert the frontend team uses.
Anything production related you are probably looking for something like Varnish.
{
"env": {
"USERNAME": "foo",
"PASSWORD": "bar",
"AUTH_BEARER": "eyJhbGcOIUz1NiJ9.foobar,bazqux",
"TARGET": "https://api.github.com/",
"MAX_WAIT_TIME": 1000,
"TTL": 5000,
"PORT": 4000,
"MODIFY_HOST_HEADER": false,
"HTTPS_PORT": 4002,
"HTTPS_KEY": "/foo/bar/ca.key",
"HTTPS_CERT": "/foo/bar/ca.crt",
"CONTENT_BLACKLIST": "<h1>We'll be back shortly</h1>|<p>Temporarily unavailable due to maintenance</p>|>Initialization failed</h1>"
}
}USERNAMEandPASSWORDare optional (if present, basic auth will be used)AUTH_BEARER(inject as authorization bearer token into header), is optionalSSLsection (cert, key, https_port) is optionalTTLis the cache item ttl in msec, use -1 for infinity, default is 5 secMODIFY_HOST_HEADERtrue replaces current host with target host in the requestCONTENT_BLACKLISTis a pipe separated list of strings (blacklisted resources will not be saved)
Defaults are in config.js.
npm i- create
nodemon.json npm run dev- add
yourhost.devas 127.0.0.1 to your hosts file (if you want it to match with your cert) - example call url: https://yourhost.dev:4000/users/octocat
All endpoints are GET, now we have a help page at /__help
example