import express from "express"; import { createServer } from "http"; import path from "path"; import { fileURLToPath } from "url"; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); async function startServer() { const app = express(); const server = createServer(app); const modernPath = path.resolve(__dirname, "..", "dist-modern"); const legacyPath = path.resolve(__dirname, "..", "dist-legacy"); app.use("/modern", express.static(modernPath)); app.use("/legacy", express.static(legacyPath)); function shouldUseLegacy(req: express.Request) { // Prefer capability detection on client, but keep a UA escape hatch for very old WebViews. const ua = req.headers["user-agent"] || ""; // Chrome 91 WebView frequently reports like: Chrome/91.0.4472.114 const m = String(ua).match(/Chrome\/(\d+)\./); if (m) return Number(m[1]) <= 91; return false; } // Bootstrap entry: redirect to /legacy or /modern while preserving hash routes. app.get(["/", "/index.html", "/i.html"], (req, res) => { const defaultToLegacy = shouldUseLegacy(req) ? "true" : "false"; res.setHeader("Content-Type", "text/html; charset=utf-8"); res.end(`