somratpro commited on
Commit
baa4b59
·
1 Parent(s): ea9c8a5

feat: add BROWSER_PORT and update proxy functions to support dynamic port routing

Browse files
Files changed (1) hide show
  1. health-server.js +7 -6
health-server.js CHANGED
@@ -6,6 +6,7 @@ const net = require("net");
6
 
7
  const PORT = 7861;
8
  const GATEWAY_PORT = 7860;
 
9
  const GATEWAY_HOST = "127.0.0.1";
10
  const startTime = Date.now();
11
  const LLM_MODEL = process.env.LLM_MODEL || "Not Set";
@@ -819,11 +820,11 @@ async function createUptimeRobotMonitor(apiKey, host) {
819
  };
820
  }
821
 
822
- function proxyHttp(req, res, proxyPath = req.url) {
823
  const proxyReq = http.request(
824
  {
825
  hostname: GATEWAY_HOST,
826
- port: GATEWAY_PORT,
827
  method: req.method,
828
  path: proxyPath,
829
  headers: buildProxyHeaders(req.headers, req.socket.remoteAddress),
@@ -880,8 +881,8 @@ function serializeUpgradeHeaders(req, remoteAddress) {
880
  return forwardedHeaders;
881
  }
882
 
883
- function proxyUpgrade(req, socket, head, proxyPath = req.url) {
884
- const proxySocket = net.connect(GATEWAY_PORT, GATEWAY_HOST);
885
 
886
  proxySocket.on("connect", () => {
887
  const requestLines = [
@@ -1014,7 +1015,7 @@ const server = http.createServer((req, res) => {
1014
  if (isDashboardAppRoute(pathname) || isAppRoute(pathname)) {
1015
  const proxyPath =
1016
  stripDashboardAppPrefix(pathname) + (parsedUrl.search || "");
1017
- proxyHttp(req, res, proxyPath);
1018
  return;
1019
  }
1020
 
@@ -1032,7 +1033,7 @@ server.on("upgrade", (req, socket, head) => {
1032
  const parsedUrl = parseRequestUrl(req.url || "/");
1033
  const proxyPath =
1034
  stripDashboardAppPrefix(pathname) + (parsedUrl.search || "");
1035
- proxyUpgrade(req, socket, head, proxyPath);
1036
  return;
1037
  }
1038
 
 
6
 
7
  const PORT = 7861;
8
  const GATEWAY_PORT = 7860;
9
+ const BROWSER_PORT = 7862;
10
  const GATEWAY_HOST = "127.0.0.1";
11
  const startTime = Date.now();
12
  const LLM_MODEL = process.env.LLM_MODEL || "Not Set";
 
820
  };
821
  }
822
 
823
+ function proxyHttp(req, res, proxyPath = req.url, proxyPort = GATEWAY_PORT) {
824
  const proxyReq = http.request(
825
  {
826
  hostname: GATEWAY_HOST,
827
+ port: proxyPort,
828
  method: req.method,
829
  path: proxyPath,
830
  headers: buildProxyHeaders(req.headers, req.socket.remoteAddress),
 
881
  return forwardedHeaders;
882
  }
883
 
884
+ function proxyUpgrade(req, socket, head, proxyPath = req.url, proxyPort = GATEWAY_PORT) {
885
+ const proxySocket = net.connect(proxyPort, GATEWAY_HOST);
886
 
887
  proxySocket.on("connect", () => {
888
  const requestLines = [
 
1015
  if (isDashboardAppRoute(pathname) || isAppRoute(pathname)) {
1016
  const proxyPath =
1017
  stripDashboardAppPrefix(pathname) + (parsedUrl.search || "");
1018
+ proxyHttp(req, res, proxyPath, BROWSER_PORT);
1019
  return;
1020
  }
1021
 
 
1033
  const parsedUrl = parseRequestUrl(req.url || "/");
1034
  const proxyPath =
1035
  stripDashboardAppPrefix(pathname) + (parsedUrl.search || "");
1036
+ proxyUpgrade(req, socket, head, proxyPath, BROWSER_PORT);
1037
  return;
1038
  }
1039