Skip to content

Commit

Permalink
fix websocket proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
Luna-devv committed Apr 15, 2023
1 parent 7719e8c commit 6147ee0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import node_proxy from 'node:http';

export const Config: ConfigType = {
port: {
http: 80,
Expand All @@ -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;
}[];
};
17 changes: 17 additions & 0 deletions src/handlers/ws.ts
Original file line number Diff line number Diff line change
@@ -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}`
});

};

0 comments on commit 6147ee0

Please sign in to comment.