aboutsummaryrefslogtreecommitdiffstats
path: root/app/middlewares/index.ts
diff options
context:
space:
mode:
authorLeonardo Bishop <me@leonardobishop.com>2023-08-08 01:21:25 +0100
committerLeonardo Bishop <me@leonardobishop.com>2023-08-08 01:21:25 +0100
commit50509a261385ed5ce6a7099257ae8c58cb006881 (patch)
treea9b3abf37cebd2bb6471e90bc99792db1a329592 /app/middlewares/index.ts
parent84cea12bd2e647f449b9133e6dcaf5312b92f321 (diff)
Add live reloading
Diffstat (limited to 'app/middlewares/index.ts')
-rw-r--r--app/middlewares/index.ts26
1 files changed, 14 insertions, 12 deletions
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();
-});
+ });
+}