兼容低内核版本的浏览器

This commit is contained in:
eafonyang
2026-06-03 15:42:58 +08:00
parent e17c096f0b
commit 56da3e0d1f
29 changed files with 1246 additions and 82 deletions
+24 -5
View File
@@ -6,23 +6,42 @@ import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const DEPLOY_PREFIX = "/x9/v2";
async function startServer() {
const app = express();
const server = createServer(app);
const staticPath = path.resolve(__dirname, "..", "dist");
const distRoot = path.resolve(__dirname, "..", "dist");
const modernPath = path.join(distRoot, "modern");
const legacyPath = path.join(distRoot, "legacy");
app.use(express.static(staticPath));
app.use(`${DEPLOY_PREFIX}/modern`, express.static(modernPath));
app.use(`${DEPLOY_PREFIX}/legacy`, express.static(legacyPath));
app.use(DEPLOY_PREFIX, express.static(distRoot));
const sendModernSpa = (_req: express.Request, res: express.Response) => {
res.sendFile(path.join(modernPath, "i.modern.html"));
};
const sendLegacySpa = (_req: express.Request, res: express.Response) => {
res.sendFile(path.join(legacyPath, "i.legacy.html"));
};
app.get(`${DEPLOY_PREFIX}/modern/*`, sendModernSpa);
app.get(`${DEPLOY_PREFIX}/legacy/*`, sendLegacySpa);
app.get([DEPLOY_PREFIX, `${DEPLOY_PREFIX}/`, `${DEPLOY_PREFIX}/i.html`], (_req, res) => {
res.sendFile(path.join(distRoot, "i.html"));
});
// Handle client-side routing — entry is i.html (see vite rollup input)
app.get("*", (_req, res) => {
res.sendFile(path.join(staticPath, "i.html"));
res.redirect(302, `${DEPLOY_PREFIX}/i.html`);
});
const port = process.env.PORT || 3000;
server.listen(port, () => {
console.log(`Server running on http://localhost:${port}/`);
console.log(`Server running on http://localhost:${port}${DEPLOY_PREFIX}/i.html`);
});
}