Mercurial
view react_games/backend/routes/web.ts @ 71:75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Sun, 28 Dec 2025 20:34:22 -0800 |
| parents | fb9bcd3145cb |
| children |
line wrap: on
line source
import { Router, static as serveStatic } from 'express'; import path from 'node:path'; type SpaMount = { baseUrl: string; // Base path like /games entryHtml: string; // we need to define its entry index html }; export function createWebRouter(publicDir: string, spaMounts: SpaMount[]) { const router = Router(); // order matters so geting just public one first router.use(serveStatic(publicDir, { index: 'index.html', extensions: ['html'], setHeaders: (res) => { res.setHeader('X-Content-Type-Options', 'nosniff'); }, })); for (const { baseUrl, entryHtml } of spaMounts) { router.get(baseUrl, (_req, res) => { res.sendFile(path.join(publicDir, entryHtml)); }); router.get(`${baseUrl}/:rest`, (_req, res) => { res.sendFile(path.join(publicDir, entryHtml)); }); } router.use((_req, res) => { res.status(404).send('Not Found'); }); return router; }