diff --git a/apps/server/src/share/routes.ts b/apps/server/src/share/routes.ts index 6494f099a7..69489c5522 100644 --- a/apps/server/src/share/routes.ts +++ b/apps/server/src/share/routes.ts @@ -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) {