somratpro commited on
Commit
2fcbf6a
·
1 Parent(s): 6345e1c

refactor: replace stripDashboardAppPrefix with mapAppProxyPath to correctly preserve application base paths

Browse files
Files changed (1) hide show
  1. health-server.js +7 -8
health-server.js CHANGED
@@ -58,14 +58,13 @@ function isLocalRoute(pathname) {
58
  );
59
  }
60
 
61
- function stripDashboardAppPrefix(path) {
62
- if (path === DASHBOARD_APP_BASE) return "/";
63
  if (path.startsWith(`${DASHBOARD_APP_BASE}/`)) {
64
- return path.slice(DASHBOARD_APP_BASE.length) || "/";
65
  }
66
- if (path === APP_BASE) return "/";
67
- if (path.startsWith(`${APP_BASE}/`)) {
68
- return path.slice(APP_BASE.length) || "/";
69
  }
70
  return path;
71
  }
@@ -1019,7 +1018,7 @@ const server = http.createServer((req, res) => {
1019
 
1020
  if (isDashboardAppRoute(pathname) || isAppRoute(pathname)) {
1021
  const proxyPath =
1022
- stripDashboardAppPrefix(pathname) + (parsedUrl.search || "");
1023
  proxyHttp(req, res, proxyPath, GATEWAY_PORT);
1024
  return;
1025
  }
@@ -1037,7 +1036,7 @@ server.on("upgrade", (req, socket, head) => {
1037
  if (isDashboardAppRoute(pathname) || isAppRoute(pathname)) {
1038
  const parsedUrl = parseRequestUrl(req.url || "/");
1039
  const proxyPath =
1040
- stripDashboardAppPrefix(pathname) + (parsedUrl.search || "");
1041
  proxyUpgrade(req, socket, head, proxyPath, GATEWAY_PORT);
1042
  return;
1043
  }
 
58
  );
59
  }
60
 
61
+ function mapAppProxyPath(path) {
62
+ if (path === DASHBOARD_APP_BASE) return APP_BASE;
63
  if (path.startsWith(`${DASHBOARD_APP_BASE}/`)) {
64
+ return `${APP_BASE}${path.slice(DASHBOARD_APP_BASE.length)}`;
65
  }
66
+ if (path === APP_BASE || path.startsWith(`${APP_BASE}/`)) {
67
+ return path;
 
68
  }
69
  return path;
70
  }
 
1018
 
1019
  if (isDashboardAppRoute(pathname) || isAppRoute(pathname)) {
1020
  const proxyPath =
1021
+ mapAppProxyPath(pathname) + (parsedUrl.search || "");
1022
  proxyHttp(req, res, proxyPath, GATEWAY_PORT);
1023
  return;
1024
  }
 
1036
  if (isDashboardAppRoute(pathname) || isAppRoute(pathname)) {
1037
  const parsedUrl = parseRequestUrl(req.url || "/");
1038
  const proxyPath =
1039
+ mapAppProxyPath(pathname) + (parsedUrl.search || "");
1040
  proxyUpgrade(req, socket, head, proxyPath, GATEWAY_PORT);
1041
  return;
1042
  }