kinaiok commited on
Commit
f5dc292
Β·
1 Parent(s): 62c2e34

Fix API routing - prevent SPA fallback from catching API requests

Browse files
Files changed (1) hide show
  1. artifacts/api-server/src/app.ts +7 -2
artifacts/api-server/src/app.ts CHANGED
@@ -50,8 +50,13 @@ app.use("/api/v1", openaiRouter);
50
  const frontendDistPath = path.join(__dirname, "../../image-gen/dist/public");
51
  app.use(express.static(frontendDistPath));
52
 
53
- // SPA fallback - εͺεœ¨ζ²’ζœ‰ζ‰Ύεˆ°ιœζ…‹ζͺ”ζ‘ˆζ™‚θΏ”ε›ž index.html
54
- app.use((req, res) => {
 
 
 
 
 
55
  res.sendFile(path.join(frontendDistPath, "index.html"));
56
  });
57
 
 
50
  const frontendDistPath = path.join(__dirname, "../../image-gen/dist/public");
51
  app.use(express.static(frontendDistPath));
52
 
53
+ // SPA fallback - εͺθ™•η†ιž API 請求
54
+ app.use((req, res, next) => {
55
+ // ε¦‚ζžœζ˜― API θ«‹ζ±‚δ½†ζ²’ζœ‰θ’«θ™•η†οΌŒθΏ”ε›ž 404
56
+ if (req.path.startsWith('/api') || req.path.startsWith('/v1')) {
57
+ return res.status(404).json({ error: 'API endpoint not found' });
58
+ }
59
+ // ε…Άδ»–θ«‹ζ±‚θΏ”ε›ž SPA ηš„ index.html
60
  res.sendFile(path.join(frontendDistPath, "index.html"));
61
  });
62