From 846aa1d392ee6ca3e14cf7165afb835fc7c523a3 Mon Sep 17 00:00:00 2001 From: Entrpix Date: Mon, 8 Jul 2024 13:20:07 -0400 Subject: [PATCH] fix rammerhead crashing --- src/server.mjs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/server.mjs b/src/server.mjs index 7d6ab00a..65aa0dce 100644 --- a/src/server.mjs +++ b/src/server.mjs @@ -93,13 +93,16 @@ app.use(helmet({ // This takes one of those files and displays it for a site visitor. // Query strings like /?j are converted into paths like /views/hidden.html // back here. Which query string converts to what is defined in routes.mjs. -router.get('/', async (req, res) => res.send(paintSource(loadTemplates(tryReadFile( - path.join(__dirname, - 'views', -// This returns the file path, and has the index page set as the home page. - '/?'.indexOf(req.url) ? pages[Object.keys(req.query)[0]] : pages.index - ) -))))); +router.get('/', async (req, res) => { + const paramKey = Object.keys(req.query)[0]; + const filePath = paramKey ? pages[paramKey] : pages.index; + + const validPath = filePath || pages.index; + + res.send(paintSource(loadTemplates(tryReadFile( + path.join(__dirname, 'views', validPath) + )))); + }); app.use(router);