diff options
author | Raphael Kabo <raphaelkabo@hey.com> | 2023-10-09 10:51:17 +0100 |
---|---|---|
committer | Raphael Kabo <raphaelkabo@hey.com> | 2023-10-09 10:51:17 +0100 |
commit | 6af99ef4c0c3a28a29bad9f4c66e41d0365234cc (patch) | |
tree | 9c04b8f204b7ed7dcd7cbff2de1b6a3e6d03d435 | |
parent | 387dbf5cb7c1f03df44731d28623b13b7dc80635 (diff) |
Fix bug when no static pages defined
-rw-r--r-- | src/lib/config.ts | 2 | ||||
-rw-r--r-- | src/routes/static.ts | 46 |
2 files changed, 25 insertions, 23 deletions
diff --git a/src/lib/config.ts b/src/lib/config.ts index 7366b59..6f142e5 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -53,7 +53,7 @@ export const frontendConfig = (): FrontendConfig => { isFederated: config.general.is_federated, emailLogoUrl: config.general.email_logo_url, showKofi: config.general.show_kofi, - showInstanceInformation: config.static_pages.length > 0, + showInstanceInformation: config.static_pages?.length > 0, staticPages: config.static_pages, version: process.env.npm_package_version || "unknown", }; diff --git a/src/routes/static.ts b/src/routes/static.ts index f57d1db..33f0225 100644 --- a/src/routes/static.ts +++ b/src/routes/static.ts @@ -6,29 +6,31 @@ import { markdownToSanitizedHTML } from "../util/markdown.js"; const config = getConfig(); const router = Router(); -config.static_pages - .filter((page) => page.path?.startsWith("/") && page.filename) - .forEach((page) => { - router.get(page.path, (_: Request, res: Response) => { - try { - if (fs.existsSync(`./static/${page.filename}`)) { - const fileBody = fs.readFileSync( - `./static/${page.filename}`, - "utf-8", - ); - const parsed = markdownToSanitizedHTML(fileBody); - return res.render("static", { - title: page.title, - content: parsed, - ...frontendConfig(), - }); +if (config.static_pages?.length) { + config.static_pages + .filter((page) => page.path?.startsWith("/") && page.filename) + .forEach((page) => { + router.get(page.path, (_: Request, res: Response) => { + try { + if (fs.existsSync(`./static/${page.filename}`)) { + const fileBody = fs.readFileSync( + `./static/${page.filename}`, + "utf-8", + ); + const parsed = markdownToSanitizedHTML(fileBody); + return res.render("static", { + title: page.title, + content: parsed, + ...frontendConfig(), + }); + } + return res.status(404).render("404", frontendConfig()); + } catch (err) { + console.error(err); + return res.status(404).render("404", frontendConfig()); } - return res.status(404).render("404", frontendConfig()); - } catch (err) { - console.error(err); - return res.status(404).render("404", frontendConfig()); - } + }); }); - }); +} export default router; |