somratpro commited on
Commit
9818fe3
·
1 Parent(s): 8c35527

refactor: align proxy path routing and n8n environment variables to native /app/ subpath support

Browse files
Files changed (2) hide show
  1. health-server.js +9 -12
  2. start.sh +2 -2
health-server.js CHANGED
@@ -313,9 +313,14 @@ const server = http.createServer(async (req, res) => {
313
  return res.end();
314
  }
315
 
316
- // 3. Proxy to n8n (strip /app prefix)
317
- let proxyPath = pathname.substring(APP_BASE.length);
318
- if (!proxyPath.startsWith("/")) proxyPath = "/" + proxyPath;
 
 
 
 
 
319
 
320
  const proxyHeaders = {
321
  ...req.headers,
@@ -334,10 +339,6 @@ const server = http.createServer(async (req, res) => {
334
  headers: proxyHeaders,
335
  },
336
  (proxyRes) => {
337
- // Rewrite Location header for redirects
338
- if (proxyRes.headers.location && proxyRes.headers.location.startsWith("/")) {
339
- proxyRes.headers.location = APP_BASE + proxyRes.headers.location;
340
- }
341
  res.writeHead(proxyRes.statusCode, proxyRes.headers);
342
  proxyRes.pipe(res);
343
  },
@@ -358,11 +359,7 @@ const server = http.createServer(async (req, res) => {
358
 
359
  server.on("upgrade", (req, socket, head) => {
360
  const url = parseRequestUrl(req.url);
361
- let proxyPath = url.pathname;
362
- if (proxyPath.startsWith(APP_BASE)) {
363
- proxyPath = proxyPath.substring(APP_BASE.length);
364
- }
365
- if (!proxyPath.startsWith("/")) proxyPath = "/" + proxyPath;
366
 
367
  const proxySocket = net.connect(TARGET_PORT, TARGET_HOST, () => {
368
  proxySocket.write(
 
313
  return res.end();
314
  }
315
 
316
+ // 3. Proxy to n8n (Pass full path as n8n is natively configured for /app/)
317
+ const proxyPath = pathname;
318
+
319
+ // Handle n8n's common 404 on root /app/ by redirecting to workflows
320
+ if (proxyPath === APP_BASE + "/" && req.method === "GET") {
321
+ res.writeHead(302, { Location: APP_BASE + "/home/workflows" });
322
+ return res.end();
323
+ }
324
 
325
  const proxyHeaders = {
326
  ...req.headers,
 
339
  headers: proxyHeaders,
340
  },
341
  (proxyRes) => {
 
 
 
 
342
  res.writeHead(proxyRes.statusCode, proxyRes.headers);
343
  proxyRes.pipe(res);
344
  },
 
359
 
360
  server.on("upgrade", (req, socket, head) => {
361
  const url = parseRequestUrl(req.url);
362
+ const proxyPath = url.pathname;
 
 
 
 
363
 
364
  const proxySocket = net.connect(TARGET_PORT, TARGET_HOST, () => {
365
  proxySocket.write(
start.sh CHANGED
@@ -15,8 +15,8 @@ mkdir -p "$N8N_HOME"
15
  SPACE_HOST_DETECTED="${SPACE_HOST_OVERRIDE:-${SPACE_HOST:-}}"
16
  if [ -n "$SPACE_HOST_DETECTED" ]; then
17
  export N8N_HOST="${N8N_HOST:-$SPACE_HOST_DETECTED}"
18
- # Internal root hosting with external subpath awareness
19
- export N8N_PATH="/"
20
  export N8N_PROTOCOL="https"
21
  export N8N_HOST="${SPACE_HOST_DETECTED}"
22
  export WEBHOOK_URL="https://${SPACE_HOST_DETECTED}/app/"
 
15
  SPACE_HOST_DETECTED="${SPACE_HOST_OVERRIDE:-${SPACE_HOST:-}}"
16
  if [ -n "$SPACE_HOST_DETECTED" ]; then
17
  export N8N_HOST="${N8N_HOST:-$SPACE_HOST_DETECTED}"
18
+ # Strict Native Subpath Configuration
19
+ export N8N_PATH="/app/"
20
  export N8N_PROTOCOL="https"
21
  export N8N_HOST="${SPACE_HOST_DETECTED}"
22
  export WEBHOOK_URL="https://${SPACE_HOST_DETECTED}/app/"