Skip to content

Commit

Permalink
adding overwrite * wildcard
Browse files Browse the repository at this point in the history
  • Loading branch information
Luna-devv committed Sep 1, 2022
1 parent 098fe68 commit 0582508
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
15 changes: 13 additions & 2 deletions src/hosts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ export default {
type: "WEB",
arc: true
},
"c.lunish.nl": {
target: 'https://lunish.nl/luna',
type: "REDIRECT",
overwrites: [
{
path: '/*',
type: "REDIRECT",
target: 'https://cdn.waya.one/{path}'
}
]
},

"waya.one": {
target: 5000,
Expand All @@ -52,9 +63,9 @@ export default {
ip: '127.0.9.1',
overwrites: [
{
path: ['/sex', '/sex2'],
path: '/*',
type: "REDIRECT",
target: 'https://google.com'
target: 'https://google.com/{path}'
}
]
}
Expand Down
6 changes: 4 additions & 2 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function requestManager(req, res) {
// managing overwrites
if (overwrites) {
for (const overwrite of overwrites) {
if (typeof overwrite.path == 'string' ? req.url == overwrite.path : overwrite.path.includes(req.url)) {
if ((typeof overwrite.path == 'string' ? req.url == overwrite.path : overwrite.path.includes(req.url)) || overwrite.path === '/*') {

// Proxy overwrite
switch (overwrite.type) {
Expand All @@ -49,8 +49,9 @@ export async function requestManager(req, res) {

case "REDIRECT":
// Redirections
if (typeof overwrite.target === 'number') return onError('Redirect target cannot be number', req, res);
res.writeHead(302, {
'Location': overwrite.target
'Location': overwrite.target.replace(/{path}/g, req.url.slice(1))
});
res.end();
break;
Expand Down Expand Up @@ -88,6 +89,7 @@ export async function requestManager(req, res) {

case "REDIRECT":
// Redirections
if (typeof target === 'number') return onError('Redirect target cannot be number', req, res);
res.writeHead(302, {
'Location': target
});
Expand Down

0 comments on commit 0582508

Please sign in to comment.