Skip to content

Commit

Permalink
allow using diffrent ips
Browse files Browse the repository at this point in the history
  • Loading branch information
Luna-devv committed Sep 1, 2022
1 parent 651c5d6 commit be317b2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ export type Host = {
target: number | string
type: "WEB" | "WS" | "REDIRECT"
arc?: true | false
ip?: string
overwrites?: {
path: string | string[]
type: "WEB" | "REDIRECT"
target: number | string
ip?: string
}[]
};
15 changes: 15 additions & 0 deletions src/hosts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@ export default {
target: 5000,
type: "WEB",
arc: true
},


"proxy.local": {
target: 3000,
type: "WEB",
arc: true,
ip: '127.0.9.1',
overwrites: [
{
path: ['/sex', '/sex2'],
type: "REDIRECT",
target: 'https://google.com'
}
]
}

}
8 changes: 4 additions & 4 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function requestManager(req, res) {
};

// Get details about the registered target
const { type, target, arc, overwrites } = hosts[req.headers.host] as Host;
const { type, target, arc, ip, overwrites } = hosts[req.headers.host] as Host;

// Enables support for arc.io
if (arc && req.url === '/arc-sw.js') {
Expand All @@ -43,7 +43,7 @@ export async function requestManager(req, res) {
// HTTP requests
case "WEB":
proxy.web(req, res, {
target: `http://127.0.0.1:${overwrite.target}`
target: `http://${overwrite.ip || '127.0.0.1'}:${overwrite.target}`
});
break;

Expand Down Expand Up @@ -75,14 +75,14 @@ export async function requestManager(req, res) {
// HTTP requests
case "WEB":
proxy.web(req, res, {
target: `http://127.0.0.1:${target}`
target: `http://${ip || '127.0.0.1'}:${target}`
});
break;

case "WS":
// WebSocket requests
proxy.ws(req, res.socket, {
target: `ws://127.0.0.1:${target}`
target: `ws://${ip || '127.0.0.1'}:${target}`
});
break;

Expand Down

0 comments on commit be317b2

Please sign in to comment.