Basic proxy script written in node.js using node:http and node-http-proxy.
This script was originally written from @flamexdev and was improved and re-written into TypeScript by me.
- Clone this repository using
git clone https://github.com/Luna-devv/proxy - Adapt the
src/hosts.tsto your needs and webservers - Install all external dependencies using
npm installoryarn install - Compile the code using
npx tsc - Run the script with PM2
pm2 start dist/app.js --name proxy
Example key for proxing a webserver:
{
"api.waya.one": {
target: 4000,
type: "WEB",
arc: false
}
}This will be the subdomain or the domain that will be proxied.
- (using
"WEB"orWS): This is the port on which your webserver runs. Please note that this musst run on the same server as this proxy script. - (using
"REDIRECT"): This is the domain/IP the proxy script will redirect to. Note that this can be any domain, it must include the protocal (i.e."https://lunish.nl/luna")
There are 3 essential types:
"WEB": You will use this if you want that for example the content of the page123.456.789:4000should be displayed onapi.waya.one."WS": You will use this if you have a (server) websocket and you want i.e. to forward it from123.456.789:4000toapi.waya.one."REDIRECT": YOu will use this if you want to redirect the user to another page, this requires settingtargetto a string.
If your site is using arc.io you can just set this value to true to enable support for it.
Note: All requests to /arc-sw.js will be catched by the proxy and will NOT reach your webserver.
If you want to to change the error pages for either a missing record (404.html) or the page for a not responding webserver (500.html), go to the /html/ file tree and start editing your plain HTML pages there.
Note: There is a {hosts} placeholder that will be replaced with the requested domain (i.e.: api.waya.one)
Feel free to open a issue, send me an E-Mail or join my Discord server.