feat: added heartbeat and fixed up gateway page

This commit is contained in:
Sheen Capadngan
2025-09-02 21:51:29 +08:00
parent 879361fd7a
commit d5dcaf0d59
13 changed files with 269 additions and 66 deletions
+6 -8
View File
@@ -9,11 +9,6 @@ import { BadRequestError } from "../errors";
import { GatewayProxyProtocol } from "../gateway/types";
import { logger } from "../logger";
/*
TODOs:
- Add heartbeat tracking to gateway connection
*/
interface IGatewayProxyServer {
server: net.Server;
port: number;
@@ -58,7 +53,9 @@ const createProxyConnection = async ({
});
socket.on("close", (hadError: boolean) => {
logger.error(`TLS connection closed${hadError ? " with error" : ""}`);
if (hadError) {
logger.error("TLS connection closed with error");
}
});
socket.on("timeout", () => {
@@ -175,6 +172,8 @@ const setupProxyServer = async ({
command += "\n";
} else if (protocol === GatewayProxyProtocol.Tcp) {
command += `FORWARD-TCP\n`;
} else if (protocol === GatewayProxyProtocol.Ping) {
command += `PING\n`;
} else {
throw new BadRequestError({
message: `Invalid protocol: ${protocol as string}`
@@ -222,7 +221,6 @@ const setupProxyServer = async ({
return;
}
console.log(`Gateway proxy started on port ${address.port}`);
resolve({
server,
port: address.port,
@@ -230,7 +228,7 @@ const setupProxyServer = async ({
try {
server.close();
} catch (err) {
console.debug("Error closing server:", err);
logger.debug("Error closing server:", err instanceof Error ? err.message : String(err));
}
},
getProxyError: () => proxyErrorMsg.join(",")
+2 -1
View File
@@ -6,7 +6,8 @@ export type TGatewayTlsOptions = { ca: string; cert: string; key: string };
export enum GatewayProxyProtocol {
Http = "http",
Tcp = "tcp"
Tcp = "tcp",
Ping = "ping"
}
export enum GatewayHttpProxyActions {