fix: make API not-found responses deterministic
TallyNote release / linux-x64 (push) Failing after 3m31s

This commit is contained in:
Qiufeng
2026-08-29 06:17:37 +08:00
parent 9719429f4a
commit cbe0d65320
4 changed files with 20 additions and 7 deletions
+16 -5
View File
@@ -1640,13 +1640,24 @@ export async function buildApp(database: DatabaseContext, config: AppConfig) {
return reply.send(await safeReadStream(config.exportsDir, job.filePath));
});
if (existsSync(config.webDir)) {
const hasWeb = existsSync(config.webDir);
if (hasWeb) {
await app.register(fastifyStatic, { root: config.webDir, wildcard: false });
app.setNotFoundHandler((request, reply) => {
if (request.url.startsWith("/api/")) return reply.code(404).send(errorPayload(request, new AppError(404, "NOT_FOUND", "接口不存在")));
return reply.sendFile("index.html");
}
// Keep API errors structured even when the production frontend has not been
// built yet (for example in a clean CI checkout or an API-only process).
app.setNotFoundHandler((request, reply) => {
if (request.url.split("?", 1)[0]!.startsWith("/api/")) {
return reply.code(404).send(errorPayload(request, new AppError(404, "NOT_FOUND", "接口不存在")));
}
if (hasWeb) return reply.sendFile("index.html");
return reply.code(404).send({
message: `Route ${request.method}:${request.url} not found`,
error: "Not Found",
statusCode: 404,
});
} else {
});
if (!hasWeb) {
app.get("/", async () => ({ name: "TallyNote", mode: "api", hint: "开发界面运行在 Vite 端口" }));
}