somratpro commited on
Commit
b38aa3e
·
1 Parent(s): feb2c08

refactor: simplify n8n routing by removing path allowlist and defaulting proxy behavior

Browse files
Files changed (1) hide show
  1. health-server.js +32 -57
health-server.js CHANGED
@@ -608,66 +608,41 @@ const server = http.createServer(async (req, res) => {
608
  );
609
  }
610
 
611
- // 2. n8n Routing Logic (Namespace-based Proxy)
612
- // These are the prefixes n8n uses. If it matches, we proxy to n8n at ROOT.
613
- const isN8nPath =
614
- pathname.startsWith("/static/") ||
615
- pathname.startsWith("/assets/") ||
616
- pathname.startsWith("/rest/") ||
617
- pathname.startsWith("/api/") ||
618
- pathname.startsWith("/webhook/") ||
619
- pathname.startsWith("/home/") ||
620
- pathname.startsWith("/auth/") ||
621
- pathname.startsWith("/login") ||
622
- pathname.startsWith("/signup") ||
623
- pathname.startsWith("/logout") ||
624
- pathname.startsWith("/nodes/") ||
625
- pathname.startsWith("/templates/") ||
626
- pathname.startsWith("/workflow") ||
627
- pathname.startsWith("/healthz");
628
-
629
-
630
-
631
- if (isN8nPath) {
632
- const proxyHeaders = {
633
- ...req.headers,
634
- host: `127.0.0.1:${TARGET_PORT}`,
635
- "x-forwarded-for": req.socket.remoteAddress,
636
- "x-forwarded-host": req.headers.host,
637
- "x-forwarded-proto": "https",
638
- };
639
 
640
- const proxyReq = http.request(
641
- {
642
- hostname: TARGET_HOST,
643
- port: TARGET_PORT,
644
- path: pathname + url.search,
645
- method: req.method,
646
- headers: proxyHeaders,
647
- },
648
- (proxyRes) => {
649
- res.writeHead(proxyRes.statusCode, proxyRes.headers);
650
- proxyRes.pipe(res);
651
- },
 
 
 
 
 
 
 
 
 
652
  );
 
653
 
654
- proxyReq.on("error", () => {
655
- res.writeHead(503, { "Content-Type": "application/json" });
656
- res.end(
657
- JSON.stringify({
658
- status: "starting",
659
- message: "n8n is initializing...",
660
- }),
661
- );
662
- });
663
-
664
- req.pipe(proxyReq);
665
- return;
666
- }
667
-
668
- // 3. Fallback: Redirect anything else to Dashboard
669
- res.writeHead(302, { Location: "/" });
670
- res.end();
671
  });
672
 
673
  server.on("upgrade", (req, socket, head) => {
 
608
  );
609
  }
610
 
611
+ // 2. n8n Proxy Logic
612
+ // Any path that isn't a dashboard route gets proxied to n8n.
613
+ const proxyHeaders = {
614
+ ...req.headers,
615
+ host: `127.0.0.1:${TARGET_PORT}`,
616
+ "x-forwarded-for": req.socket.remoteAddress,
617
+ "x-forwarded-host": req.headers.host,
618
+ "x-forwarded-proto": "https",
619
+ };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
620
 
621
+ const proxyReq = http.request(
622
+ {
623
+ hostname: TARGET_HOST,
624
+ port: TARGET_PORT,
625
+ path: pathname + url.search,
626
+ method: req.method,
627
+ headers: proxyHeaders,
628
+ },
629
+ (proxyRes) => {
630
+ res.writeHead(proxyRes.statusCode, proxyRes.headers);
631
+ proxyRes.pipe(res);
632
+ },
633
+ );
634
+
635
+ proxyReq.on("error", () => {
636
+ res.writeHead(503, { "Content-Type": "application/json" });
637
+ res.end(
638
+ JSON.stringify({
639
+ status: "starting",
640
+ message: "n8n is initializing...",
641
+ }),
642
  );
643
+ });
644
 
645
+ req.pipe(proxyReq);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
646
  });
647
 
648
  server.on("upgrade", (req, socket, head) => {