Handle stale frontend assets and harden worker startup

这个提交包含在:
cryptocommuniums-afk
2026-03-15 02:57:44 +08:00
父节点 e43b969d28
当前提交 585fd5773d
修改 3 个文件,包含 73 行新增5 行删除

查看文件

@@ -13,9 +13,17 @@ export function serveStatic(app: Express) {
);
}
app.use(express.static(distPath));
app.use(express.static(distPath, { index: false }));
app.use("*", (req, res) => {
// Missing files under /assets or any path with an extension must return 404.
// Falling back to index.html causes browsers to report MIME errors on stale chunks.
const requestPath = req.originalUrl.split("?")[0];
if (path.extname(requestPath)) {
res.status(404).type("text/plain").send("Not found");
return;
}
app.use("*", (_req, res) => {
res.sendFile(path.resolve(distPath, "index.html"));
});
}

查看文件

@@ -35,9 +35,14 @@ async function workOnce() {
async function main() {
console.log(`[worker] ${workerId} started`);
for (;;) {
const hasWorked = await workOnce();
if (!hasWorked) {
await sleep(ENV.backgroundTaskPollMs);
try {
const hasWorked = await workOnce();
if (!hasWorked) {
await sleep(ENV.backgroundTaskPollMs);
}
} catch (error) {
console.error("[worker] loop error", error);
await sleep(Math.max(ENV.backgroundTaskPollMs, 3_000));
}
}
}