Spaces:
Paused
Paused
refactor: simplify n8n routing by removing path allowlist and defaulting proxy behavior
Browse files607 unmodified lines608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673607 unmodified lines);}// 2. n8n Routing Logic (Namespace-based Proxy)// These are the prefixes n8n uses. If it matches, we proxy to n8n at ROOT.const isN8nPath =pathname.startsWith("/static/") ||pathname.startsWith("/assets/") ||pathname.startsWith("/rest/") ||pathname.startsWith("/api/") ||pathname.startsWith("/webhook/") ||pathname.startsWith("/home/") ||pathname.startsWith("/auth/") ||pathname.startsWith("/login") ||pathname.startsWith("/signup") ||pathname.startsWith("/logout") ||pathname.startsWith("/nodes/") ||pathname.startsWith("/templates/") ||pathname.startsWith("/workflow") ||pathname.startsWith("/healthz");if (isN8nPath) {const proxyHeaders = {...req.headers,host: `127.0.0.1:${TARGET_PORT}`,"x-forwarded-for": req.socket.remoteAddress,"x-forwarded-host": req.headers.host,"x-forwarded-proto": "https",};const proxyReq = http.request({hostname: TARGET_HOST,port: TARGET_PORT,path: pathname + url.search,method: req.method,headers: proxyHeaders,},(proxyRes) => {res.writeHead(proxyRes.statusCode, proxyRes.headers);proxyRes.pipe(res);},);proxyReq.on("error", () => {res.writeHead(503, { "Content-Type": "application/json" });res.end(JSON.stringify({status: "starting",message: "n8n is initializing...",}),);});req.pipe(proxyReq);return;}// 3. Fallback: Redirect anything else to Dashboardres.writeHead(302, { Location: "/" });res.end();});server.on("upgrade", (req, socket, head) => {607 unmodified lines608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648607 unmodified lines);}// 2. n8n Proxy Logic// Any path that isn't a dashboard route gets proxied to n8n.const proxyHeaders = {...req.headers,host: `127.0.0.1:${TARGET_PORT}`,"x-forwarded-for": req.socket.remoteAddress,"x-forwarded-host": req.headers.host,"x-forwarded-proto": "https",};const proxyReq = http.request({hostname: TARGET_HOST,port: TARGET_PORT,path: pathname + url.search,method: req.method,headers: proxyHeaders,},(proxyRes) => {res.writeHead(proxyRes.statusCode, proxyRes.headers);proxyRes.pipe(res);},);proxyReq.on("error", () => {res.writeHead(503, { "Content-Type": "application/json" });res.end(JSON.stringify({status: "starting",message: "n8n is initializing...",}),);});req.pipe(proxyReq);});server.on("upgrade", (req, socket, head) => {
health-server.js+32-57