k-l-lambda Claude commited on
Commit
001aa74
·
1 Parent(s): f553531

fix: exclude static files from SPA catch-all route

Browse files

Files with extensions (.onnx, .wasm, etc.) now bypass the SPA handler,
allowing the static middleware to serve them correctly. This fixes
ONNX model loading which was incorrectly returning index.html.

Co-Authored-By: Claude <noreply@anthropic.com>

Files changed (1) hide show
  1. trigo-web/backend/src/server.ts +7 -1
trigo-web/backend/src/server.ts CHANGED
@@ -72,11 +72,17 @@ if (process.env.NODE_ENV === "production") {
72
  const frontendPath = path.join(__dirname, "../../app/dist");
73
  app.use(express.static(frontendPath));
74
 
75
- // Serve index.html for all routes (SPA support)
76
  app.get("*", (req: any, res: any, next: any) => {
 
77
  if (req.path.startsWith("/health") || req.path.startsWith("/socket.io")) {
78
  return next();
79
  }
 
 
 
 
 
80
  res.sendFile(path.join(frontendPath, "index.html"));
81
  });
82
  }
 
72
  const frontendPath = path.join(__dirname, "../../app/dist");
73
  app.use(express.static(frontendPath));
74
 
75
+ // Serve index.html for SPA routes (paths without file extensions)
76
  app.get("*", (req: any, res: any, next: any) => {
77
+ // Skip API and socket.io routes
78
  if (req.path.startsWith("/health") || req.path.startsWith("/socket.io")) {
79
  return next();
80
  }
81
+ // Skip requests for files with extensions (let static middleware handle them or return 404)
82
+ if (path.extname(req.path)) {
83
+ return next();
84
+ }
85
+ // Serve index.html for SPA navigation routes
86
  res.sendFile(path.join(frontendPath, "index.html"));
87
  });
88
  }