增加兼容低版本内核的页面
This commit is contained in:
+49
-4
@@ -10,13 +10,58 @@ async function startServer() {
|
||||
const app = express();
|
||||
const server = createServer(app);
|
||||
|
||||
const staticPath = path.resolve(__dirname, "..", "dist");
|
||||
const modernPath = path.resolve(__dirname, "..", "dist-modern");
|
||||
const legacyPath = path.resolve(__dirname, "..", "dist-legacy");
|
||||
|
||||
app.use(express.static(staticPath));
|
||||
app.use("/modern", express.static(modernPath));
|
||||
app.use("/legacy", express.static(legacyPath));
|
||||
|
||||
// Handle client-side routing — entry is i.html (see vite rollup input)
|
||||
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(`<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1" />
|
||||
<title>Luxsin X8 Controller</title>
|
||||
<script>
|
||||
(function () {
|
||||
function supportsModernCss() {
|
||||
try {
|
||||
return (
|
||||
typeof CSS !== "undefined" &&
|
||||
CSS.supports("color", "color-mix(in srgb, red 50%, blue)") &&
|
||||
CSS.supports("height", "100dvh")
|
||||
);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
var useLegacy = ${defaultToLegacy} || !supportsModernCss();
|
||||
var prefix = useLegacy ? "/x8/v2/legacy/" : "/x8/v2/modern/";
|
||||
// Hash router: keep location.hash
|
||||
location.replace(prefix + (location.hash || "#/"));
|
||||
})();
|
||||
</script>
|
||||
</head>
|
||||
<body></body>
|
||||
</html>`);
|
||||
});
|
||||
|
||||
// Hash routing: any other path should serve the bootstrap as well.
|
||||
app.get("*", (_req, res) => {
|
||||
res.sendFile(path.join(staticPath, "i.html"));
|
||||
res.redirect(302, "/x8/v2/");
|
||||
});
|
||||
|
||||
const port = process.env.PORT || 3000;
|
||||
|
||||
Reference in New Issue
Block a user