verybasic-http-proxy
A very basic http proxy in nodejs.
You may use it to quickly get around CORS limitations for APIs you want to query from browser
Installation
npm i verybasic-http-proxy
Starting the proxy
using the cli
with global install
verybasic-http-proxy --port 5555
with local install
npx verybasic-http-proxy --port 5555
via package.json scripts
"scripts": {
"proxy": "verybasic-http-proxy --port 5555"
}
from script
const createProxy = require('verybasic-http-proxy')
createProxy(5555)
Port is optional, default is 5555
Forwarding requests
Prepend the proxy url to your request, for instance
http://localhost:5555/https://www.someapi.com?par=val
All your request headers and data are forwarded.
The only hardcoded request headers are Host, Origin and Referer so to match the requested api. Hop-by-hop headers and body framing headers (Content-Length, Transfer-Encoding, Accept-Encoding) are recalculated by the proxy.
Response headers will include
access-control-allow-origin: <the origin that called the proxy>
access-control-allow-credentials: true
so both plain and credentialed (cookies / withCredentials) requests work.
OPTIONS preflights are answered with 204 and echo back the requested method and headers,
plus access-control-allow-private-network: true for Chrome's Local Network Access checks.
Every request, preflights included, is logged to stdout as METHOD /url.