import path from 'node:path'; import express from 'express'; import cookieParser from 'cookie-parser'; import config from './config.js'; import './db/index.js'; import { loadUser } from './auth/middleware.js'; import authRoutes from './auth/routes.js'; import profileRoutes from './profile/routes.js'; import historyRoutes from './history/routes.js'; import historyRecordRoutes from './history/recordRoutes.js'; import wordRoutes from './words/wordRoutes.js'; import { listGames } from './games/registry.js'; const app = express(); app.use(express.json({ limit: '1mb' })); app.use(cookieParser()); app.use(loadUser); app.get('/api/health', (_req, res) => res.json({ ok: true })); app.get('/api/games', (_req, res) => res.json({ games: listGames() })); app.use('/api/auth', authRoutes); app.use('/api/profile', profileRoutes); app.use('/api/history', historyRoutes); app.use('/api/history', historyRecordRoutes); app.use('/api/words', wordRoutes); app.use(express.static(config.publicDir, { extensions: ['html'] })); app.get('*', (_req, res) => { res.sendFile(path.join(config.publicDir, 'index.html')); }); app.use((err, _req, res, _next) => { console.error('[server]', err); res.status(500).json({ error: 'Internal server error.' }); }); app.listen(config.port, config.host, () => { console.log(`[server] listening on http://${config.host}:${config.port}`); });