diff react_games/backend/server.ts @ 37:fb9bcd3145cb

[ReactGames] Few games I made using react just to practice few things.
author MrJuneJune <me@mrjunejune.com>
date Mon, 01 Dec 2025 20:22:47 -0800
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/react_games/backend/server.ts	Mon Dec 01 20:22:47 2025 -0800
@@ -0,0 +1,26 @@
+import express from 'express';
+import path from 'node:path';
+import { createTodoRouter } from './routes/todo';
+import { createWebRouter } from './routes/web';
+import { createWorldeRouter } from './routes/wordle';
+
+const app = express();
+app.use(express.json());
+
+const ROOT = process.cwd();
+const PUBLIC_DIR = path.resolve(ROOT, 'public');
+const DATA_FILE  = path.resolve(ROOT, 'data', 'todos.json');
+const PORT = Number(process.env.PORT) || 4000;
+
+const SPA_MOUNTS = [
+  { baseUrl: '/games', entryHtml: 'games/index.html' },
+];
+
+app.use('/api/v1/todo', createTodoRouter(DATA_FILE));
+app.use('/api/v1/wordle', createWorldeRouter());
+app.use('/', createWebRouter(PUBLIC_DIR, SPA_MOUNTS));
+
+app.listen(PORT, () => {
+  console.log(`→ http://localhost:${PORT}`);
+});
+