view react_games/backend/routes/web.ts @ 279:b3b547563ec7

Add Google connector service and agent wiki Implement the C/Seobeo Google Drive and Gmail connector with encrypted OAuth storage, Zenbu authentication, browser testing, AI tool discovery, chunked HTTP decoding, and Bazel coverage. Consolidate repository guidance into progressive wiki documentation and enforce arena-first allocation for new first-party C code. Co-authored-by: Copilot <[email protected]> Copilot-Session: 84c338fd-0939-4bb3-b7f3-1062eb213e5d
author MrJuneJune <me@mrjunejune.com>
date Mon, 17 Aug 2026 22:22:36 -0700
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;
}