From be956d305fc697894c825113b2b891e4f97f2960 Mon Sep 17 00:00:00 2001 From: Bingus_Violet Date: Thu, 8 Feb 2024 17:30:52 -0600 Subject: [PATCH] 404 page functions --- index.js | 16 +--------------- pageUpdater.js | 43 ++++++++++++++++++++++++++----------------- 2 files changed, 27 insertions(+), 32 deletions(-) diff --git a/index.js b/index.js index b6da12b..d4c9e6c 100644 --- a/index.js +++ b/index.js @@ -166,18 +166,4 @@ function socketeer() { }) } -socketeer() - -// app.get('/index.html', async (req, res) => { -// console.log(req.params[0]) -// var html = await (pageUpdate(req.params[0])) -// res.send(minify.minify(html)) -// }) - -app.use((req, res, next) => { - res.status(404).send(` - -

404

-

Uh oh... I think your lost? There's nothing here :P

- `) -}) \ No newline at end of file +socketeer() \ No newline at end of file diff --git a/pageUpdater.js b/pageUpdater.js index 980884f..8e40a88 100644 --- a/pageUpdater.js +++ b/pageUpdater.js @@ -1,5 +1,5 @@ const path = require('path'), -fs = require('fs') + fs = require('fs') var config = JSON.parse(fs.readFileSync(path.join(__dirname, 'config.json'))) var highlightedWords = config.highlightedWords @@ -34,7 +34,7 @@ function makeStars() { right: calc(${rando}vw); } }` - + } html += "" @@ -56,22 +56,31 @@ function converter(html) { return html } -module.exports = { middleWare: function(req, res, next) { - - var filePath = req.baseUrl + req.path - if (filePath.trim() == "/") { - filePath = "/index.html" +module.exports = { + middleWare: function (req, res, next) { + + var filePath = req.baseUrl + req.path + if (filePath.trim() == "/") { + filePath = "/index.html" + } + filePath = path.join(__dirname, 'static', filePath || 'index.html') + if (fs.existsSync(filePath)) { + var data = fs.readFileSync(filePath).toString() + if (req.path.includes("style.css")) { + res.setHeader("Content-Type", "text/css") + res.send(data) + } else { + data = converter(data) + res.send(data) + } + } else { + res.status(404).send(` + +

404

+

Uh oh... I think your lost? There's nothing here :P

+ `) + } } - filePath = path.join(__dirname, 'static', filePath || 'index.html') - var data = fs.readFileSync(filePath).toString() - if (req.path.includes("style.css")) { - res.setHeader("Content-Type", "text/css") - res.send(data) - } else { - data = converter(data) - res.send(data) - } -} } async function updateCommits() {