From 50509a261385ed5ce6a7099257ae8c58cb006881 Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Tue, 8 Aug 2023 01:21:25 +0100 Subject: Add live reloading --- app/middlewares/index.ts | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'app/middlewares/index.ts') diff --git a/app/middlewares/index.ts b/app/middlewares/index.ts index 81431ca..b5fcd34 100644 --- a/app/middlewares/index.ts +++ b/app/middlewares/index.ts @@ -1,16 +1,18 @@ import { PageDirectory } from "../pages.js"; -export const page = ((req, res, next) => { - const path = req.originalUrl == "/" ? 'index' : req.originalUrl.substring(1); - res.locals.path = path; - - const page = PageDirectory.get(path); +export const directory = (pageDirectory: PageDirectory) => { + return ((req, res, next) => { + const path = req.originalUrl == "/" ? 'index' : req.originalUrl.substring(1); + res.locals.path = path; + + const page = pageDirectory.get(path); + + if (!page) { + next(); + return; + } - if (!page) { + res.locals.page = page; next(); - return; - } - - res.locals.page = page; - next(); -}); + }); +} -- cgit v1.2.3-70-g09d2