Private
Public Access
1
0

refacto: Keeping entrypoints clean and making files by purpose

This commit is contained in:
gauvainboiche
2026-03-29 13:28:18 +02:00
parent 79cf3ca13e
commit 84af90e81e
13 changed files with 1198 additions and 1167 deletions

25
server/app.js Normal file
View File

@@ -0,0 +1,25 @@
import express from "express";
import path from "path";
import { fileURLToPath } from "url";
import authRouter from "./routes/auth.js";
import gameRouter from "./routes/game.js";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const publicDir = path.join(__dirname, "..", "public");
const app = express();
app.use(express.json());
app.use(express.static(publicDir));
app.use("/api/auth", authRouter);
app.use("/api", gameRouter);
// Catch-all: serve index.html for non-API routes (SPA fallback)
app.get("*", (req, res) => {
if (req.path.startsWith("/api")) {
return res.status(404).json({ error: "not_found" });
}
res.sendFile(path.join(publicDir, "index.html"));
});
export default app;