diff --git a/src/config.ts b/src/config.ts index 6f5c9ce..1b468ff 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,3 +1,5 @@ +import node_proxy from 'node:http'; + export const Config: ConfigType = { port: { http: 80, @@ -17,15 +19,16 @@ type ConfigType = { }; export type Host = { - target: number | string - type: "WEB" | "WS" | "REDIRECT" - arc?: true | false - ip?: string + target: number | string; + type: "WEB" | "WS" | "REDIRECT"; + arc?: boolean; + ip?: string; + overwrites?: { - path: string | string[] - type: "WEB" | "REDIRECT" - target: number | string - ip?: string - ignoreIfTrue?: (req) => boolean; - }[] + path: string | string[]; + type: "WEB" | "REDIRECT"; + target: number | string; + ip?: string; + ignoreIfTrue?: (req: node_proxy.IncomingMessage) => boolean; + }[]; }; \ No newline at end of file diff --git a/src/handlers/ws.ts b/src/handlers/ws.ts new file mode 100644 index 0000000..7b23d52 --- /dev/null +++ b/src/handlers/ws.ts @@ -0,0 +1,17 @@ +import node_proxy from 'node:http'; +import { Socket } from 'node:net'; + +import { proxy } from '.'; +import { Host } from '../config'; +import hosts from '../hosts'; + +export async function handle(req: node_proxy.IncomingMessage, socket: Socket, head: Buffer) { + + const { ip, target } = hosts[req.headers.host || ''] as Host; + if (!target) return; + + proxy.ws(req, socket, head, { + target: `http://${ip || '127.0.0.1'}:${target}` + }); + +}; \ No newline at end of file