Add explicit root route and fix SPA fallback
Browse files- Added explicit / route to serve index.html directly
- Fixed SPA fallback to not intercept API routes
- Should resolve connection issues with the frontend
- server/vite.ts +17 -2
server/vite.ts
CHANGED
@@ -145,8 +145,23 @@ export function serveStatic(app: Express) {
|
|
145 |
console.log("π Serving static files from:", distPath);
|
146 |
app.use(express.static(distPath));
|
147 |
|
148 |
-
//
|
149 |
-
app.get("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
const indexPath = path.resolve(distPath, "index.html");
|
151 |
console.log("π Fallback serving: index.html from:", indexPath);
|
152 |
|
|
|
145 |
console.log("π Serving static files from:", distPath);
|
146 |
app.use(express.static(distPath));
|
147 |
|
148 |
+
// Explicit root route
|
149 |
+
app.get("/", (_req, res) => {
|
150 |
+
const indexPath = path.resolve(distPath, "index.html");
|
151 |
+
console.log("π Root route: serving index.html from:", indexPath);
|
152 |
+
if (fs.existsSync(indexPath)) {
|
153 |
+
res.sendFile(indexPath);
|
154 |
+
} else {
|
155 |
+
res.status(500).send("Frontend build not found");
|
156 |
+
}
|
157 |
+
});
|
158 |
+
|
159 |
+
// SPA fallback - serve index.html for non-API routes
|
160 |
+
app.get("*", (req, res) => {
|
161 |
+
// Don't intercept API routes
|
162 |
+
if (req.path.startsWith('/api/')) {
|
163 |
+
return res.status(404).json({ error: 'API endpoint not found' });
|
164 |
+
}
|
165 |
const indexPath = path.resolve(distPath, "index.html");
|
166 |
console.log("π Fallback serving: index.html from:", indexPath);
|
167 |
|