mirror of
https://github.com/zadam/trilium.git
synced 2026-03-21 15:53:37 +01:00
fix: limit the scope of DB check only for share page
This commit is contained in:
parent
e9987b40e6
commit
b29ab93fd5
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user