fix: limit the scope of DB check only for share page

This commit is contained in:
JYC333 2026-03-19 11:46:35 +00:00
parent e9987b40e6
commit b29ab93fd5

View File

@ -1,6 +1,6 @@
import safeCompare from "safe-compare";
import type { Request, Response, Router } from "express";
import type { NextFunction, Request, Response, Router } from "express";
import shaca from "./shaca/shaca.js";
import shacaLoader from "./shaca/shaca_loader.js";
@ -12,13 +12,15 @@ import { getDefaultTemplatePath, renderNoteContent } from "./content_renderer.js
import utils from "../services/utils.js";
import { isShareDbReady } from "./sql.js";
function assertShareDbReady(res: Response): boolean {
function assertShareDbReady(_req: Request, res: Response, next: NextFunction) {
if (!isShareDbReady()) {
res.status(503).send("The application is still initializing. Please try again in a moment.");
return false;
return;
}
return true;
next();
}
function addNoIndexHeader(note: SNote, res: Response) {
if (note.isLabelTruthy("shareDisallowRobotIndexing")) {
res.setHeader("X-Robots-Tag", "noindex");
@ -124,12 +126,7 @@ function render404(res: Response) {
function register(router: Router) {
// Guard: if the share DB is not yet initialized, return 503 for all /share routes.
router.use((_req: Request, res: Response, next) => {
if (!assertShareDbReady(res)) {
return;
}
next();
});
router.use("/share", assertShareDbReady);
function renderNote(note: SNote, req: Request, res: Response) {
if (!note) {