Implement deterministic website build engine

This commit is contained in:
2026-07-23 13:36:17 -07:00
parent 3af326a1fa
commit a27ec7bf0c
8 changed files with 847 additions and 128 deletions
+8 -32
View File
@@ -1,7 +1,6 @@
import express from "express";
import path from "path";
import fs from "fs";
import crypto from "crypto";
import { createServer as createViteServer } from "vite";
import { store } from "./src/backend/store";
import { CredentialRef } from "./src/types";
@@ -561,41 +560,18 @@ async function startServer() {
store.builds.find((b) => b.isActiveLocal) || store.builds[0];
let pageRoute = (req.query.route as string) || "/";
const rootDir = "/tmp/labyricorn-builds/current";
const rootDir = store.getCurrentBuildDirectory();
if (fs.existsSync(rootDir)) {
if (pageRoute === "/") {
// Try to list all generated pages to simulate an index
let links = "";
try {
const items = store.contentItems;
links = items
.map(
(item) =>
`<li><a href="#" onclick="window.parent.postMessage({type:'NAVIGATE_LIVE_SITE', route:'${item.route}'}, '*')">${item.title}</a></li>`,
)
.join("");
} catch (e) {}
return res.send(`
<!DOCTYPE html>
<html>
<head>
<title>Labyricorn Projection</title>
<style>body { font-family: system-ui; padding: 2rem; background: #fff; color: #111; }</style>
</head>
<body>
<h1>Local Canonical Site</h1>
<p>Generated Projection from Repository Artifacts</p>
<ul>${links}</ul>
</body>
</html>
`);
const routeWithoutQuery = pageRoute.split(/[?#]/, 1)[0].replace(/\\/g, "/");
const relativeRoute = routeWithoutQuery.replace(/^\/+/, "");
const rootPath = `${path.resolve(rootDir)}${path.sep}`;
const targetPath = path.resolve(rootDir, relativeRoute, "index.html");
if (!targetPath.startsWith(rootPath)) {
return res.status(400).json({ error: "Invalid preview route" });
}
const targetPath = path.join(rootDir, pageRoute, "index.html");
if (fs.existsSync(targetPath)) {
return res.send(fs.readFileSync(targetPath, "utf-8"));
return res.type("html").send(fs.readFileSync(targetPath, "utf-8"));
}
}