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() 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

@ -56,13 +56,15 @@ function converter(html) {
return html return html
} }
module.exports = { middleWare: function(req, res, next) { module.exports = {
middleWare: function (req, res, next) {
var filePath = req.baseUrl + req.path var filePath = req.baseUrl + req.path
if (filePath.trim() == "/") { if (filePath.trim() == "/") {
filePath = "/index.html" filePath = "/index.html"
} }
filePath = path.join(__dirname, 'static', filePath || 'index.html') filePath = path.join(__dirname, 'static', filePath || 'index.html')
if (fs.existsSync(filePath)) {
var data = fs.readFileSync(filePath).toString() var data = fs.readFileSync(filePath).toString()
if (req.path.includes("style.css")) { if (req.path.includes("style.css")) {
res.setHeader("Content-Type", "text/css") res.setHeader("Content-Type", "text/css")
@ -71,6 +73,13 @@ module.exports = { middleWare: function(req, res, next) {
data = converter(data) data = converter(data)
res.send(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>
`)
}
} }
} }