fix(server): serve updated static assets dynamically and restart stale server on .deb upgrade
CI / build (push) Waiting to run

This commit is contained in:
Schwitzz
2026-11-02 14:08:46 -06:00
parent b01073eac0
commit 8b208affc4
2 changed files with 19 additions and 1 deletions
+16 -1
View File
@@ -605,8 +605,9 @@ export async function buildApp() {
const webRoot =
process.env.PUBSCRIPT_WEB_DIST || resolve(here, "../../apps/web/dist");
if (existsSync(webRoot) && existsSync(resolve(webRoot, "index.html"))) {
const resolvedWebRoot = resolve(webRoot);
await app.register(fastifyStatic, {
root: webRoot,
root: resolvedWebRoot,
prefix: "/",
wildcard: false,
});
@@ -616,6 +617,20 @@ export async function buildApp() {
!req.url.startsWith("/api/") &&
!req.url.startsWith("/ws")
) {
const cleanPath = decodeURIComponent((req.url.split("?")[0] ?? "/").replace(/^\/+/, ""));
if (cleanPath && !cleanPath.includes("..")) {
const candidate = resolve(resolvedWebRoot, cleanPath);
if (
candidate.startsWith(resolvedWebRoot) &&
existsSync(candidate) &&
statSync(candidate).isFile()
) {
return reply.sendFile(cleanPath);
}
}
if (cleanPath.startsWith("assets/")) {
return reply.code(404).send({ error: "asset_not_found" });
}
return reply.sendFile("index.html");
}
return reply.code(404).send({ error: "not_found" });