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
+3
View File
@@ -148,6 +148,9 @@ fi
if command -v gtk-update-icon-cache >/dev/null 2>&1; then if command -v gtk-update-icon-cache >/dev/null 2>&1; then
gtk-update-icon-cache -q -t -f /usr/share/icons/hicolor || true gtk-update-icon-cache -q -t -f /usr/share/icons/hicolor || true
fi fi
# Stop any stale background server from a previous package build so the next
# launch or systemd restart serves the updated /opt/pubscript bundle cleanly.
pkill -f "/opt/pubscript/server/dist/server.mjs" >/dev/null 2>&1 || true
exit 0 exit 0
EOF EOF
chmod 0755 "$STAGE_DIR/DEBIAN/postinst" chmod 0755 "$STAGE_DIR/DEBIAN/postinst"
+16 -1
View File
@@ -605,8 +605,9 @@ export async function buildApp() {
const webRoot = const webRoot =
process.env.PUBSCRIPT_WEB_DIST || resolve(here, "../../apps/web/dist"); process.env.PUBSCRIPT_WEB_DIST || resolve(here, "../../apps/web/dist");
if (existsSync(webRoot) && existsSync(resolve(webRoot, "index.html"))) { if (existsSync(webRoot) && existsSync(resolve(webRoot, "index.html"))) {
const resolvedWebRoot = resolve(webRoot);
await app.register(fastifyStatic, { await app.register(fastifyStatic, {
root: webRoot, root: resolvedWebRoot,
prefix: "/", prefix: "/",
wildcard: false, wildcard: false,
}); });
@@ -616,6 +617,20 @@ export async function buildApp() {
!req.url.startsWith("/api/") && !req.url.startsWith("/api/") &&
!req.url.startsWith("/ws") !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.sendFile("index.html");
} }
return reply.code(404).send({ error: "not_found" }); return reply.code(404).send({ error: "not_found" });