-
Notifications
You must be signed in to change notification settings - Fork 6
2. Edit Host Entries
All the configuration for the domains are in the src/hosts.ts
file.
If you are not sure how to not break the syntax, I recommend you using code.visualstudio.com on your computer.
If you know how to do it, use nano /root/proxy/src/hosts.ts
to start editing the file.
This is an 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:4000
should 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:4000
toapi.waya.one
. -
"REDIRECT"
: YOu will use this if you want to redirect the user to another page, this requires settingtarget
to 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: ['/alphabet', '/abc', 'xyz'],
type: "REDIRECT",
target: 'https://abc.xyz',
ip: '127.0.9.1',
ignoreIfTrue: (req) => req.url.includes('.css') || req.url.includes('.js')
},
{
path: '/search/*',
type: "REDIRECT",
target: 'https://google.com/search?q={after_path}'
}
]
}
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.
You can add as many as you need and also mix them. Pay attention that you do not overwrite the same path twice, else it lower overwrite will be ignored.
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.
Example of both variants:
- Singel:
path: '/abc'
- Multiple:
path: ['/alphabet', '/abc', 'xyz']
(doesn't support wildcards)
/*
This allows you to overwrite all requests with any path. ([overwrite].path
must be string)
https://example.com/test/abc
will automatically lead to[overwrite].target/test/abc
https://example.com/
will not be overwritten by this
/search/*
Allows you to only overwrite paths behind /search/
(excluding /search
itself)
https://example.com/search/abc
will automatically lead to[overwrite].target/searcg/abc
https://example.com/search/
will not be overwritten by this
This value can only be a String, this key is required inside of overwrites
.
For more reference please go to #target.
-
{total_path}
this represents the whole url path of the proxied domain.-
https://example.com/test/abc/123?q=1 =
/test/abc/123
-
https://example.com/test/abc/123?q=1 =
-
{after_path}
this represents the whole url path of the proxied domain after the wildcard (/*
). -
{query}
this represents the whole query strings.-
https://example.com/?q=1 =
/?q=1
-
https://example.com/?q=1 =
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.
This value can only be a String, this key is optional inside of overwrites
.
For more reference please go to #ip.
This value can only be a Function and must return a Boolean, this key is optional inside of overwrites
.
This function will be always executed when the overwrite takes affect. If true
is returned, the overwrite won't be executed, if falsey-value is returned or the function doesn't exist on your host entry, the overwrite will be executed as normal.
Example: ignoreIfTrue: (req) => req.url.includes('.css') || req.url.includes('.js')
If the url either inculdes .css
or .js
, the overwrite will be ignored.
If you need help with this, feel free to open a issue, send me an E-Mail or join my Discord server.