404 page functions

This commit is contained in:
Bingus_Violet 2024-02-08 17:30:52 -06:00
parent 737c788c76
commit be956d305f
2 changed files with 27 additions and 32 deletions

View file

@ -167,17 +167,3 @@ 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(`
<link rel="stylesheet" href="/style.css">
<h1>404</h1>
<p>Uh oh... I think your lost? There's nothing here :P</p>
`)
})

View file

@ -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
@ -56,13 +56,15 @@ function converter(html) {
return html
}
module.exports = { middleWare: function(req, res, next) {
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")
@ -71,7 +73,14 @@ module.exports = { middleWare: function(req, res, next) {
data = converter(data)
res.send(data)
}
}
} else {
res.status(404).send(`
<link rel="stylesheet" href="/style.css">
<h1>404</h1>
<p>Uh oh... I think your lost? There's nothing here :P</p>
`)
}
}
}
async function updateCommits() {