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 object for proxing a webserver:
{
"proxy.local": {
target: 3000,
type: "WEB"
}
}This value can only be a String, this key is required.
This will be the subdomain (subdomain.proxy.local) or the domain (proxy.local) that will be managed.
This value can only be a String, this key is required.
- (using
"WEB"or"WS"): 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")
This value can only be WEB, WS or REDIRECT, this key is required.
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 you want to do more complex stuff with the proxy, you can do that too.
Here is an example object with all possible configurations:
"proxy.local": {
target: 3000,
type: "WEB",
arc: true,
ip: '127.0.9.1',
overwrites: [
{
path: ['/sex', '/sex2'],
target: 'https://google.com',
type: "REDIRECT"
}
]
}This value can only be true or false, this key is optional.
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.
This value can only be a String, this key is optional.
By default, this script will proxy using the local 127.0.0.1 IP. If you use docker or generally want to proxy domains for different servers, you can simply change this value to any other IP address.
This value can only be a Overwrites Array, this key is optional.
Overwrites are made to redirect or proxy only specific parts (routes) of the domain and not the whole domain at once.
This value can only be a String or a String Array, this key is required inside of overwrites.
This will represent the path(s) that will be overwritten. It can be either one (a String) or multiple (an Array) like in the example object above.
Note: All requests to this/these path(s) will be catched by the proxy and will NOT reach your webserver.
This value can only be a String, this key is required inside of overwrites.
For more reference please go to #target.
This value can only be WEB or REDIRECT, this key is required inside of overwrites.
For more reference please go to #type.
Note: WS (websockets) aren't supported as overwrite.
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.: proxy.local)
Feel free to open a issue, send me an E-Mail or join my Discord server.