summaryrefslogtreecommitdiff
path: root/app.js
diff options
context:
space:
mode:
authorMhykol <mchaeldonald62@pm.me>2024-06-01 05:24:12 -0400
committerMhykol <mchaeldonald62@pm.me>2024-06-01 05:24:12 -0400
commitd77233fe518c2c6ca5653bbb18a7fb94bade0cb9 (patch)
treee6c593b48e97a2288ed72ce37006aff2e6252b7d /app.js
parenteba79e3bd4d0e845008bc2e7ac318406f487f241 (diff)
Update app.js
Diffstat (limited to 'app.js')
-rw-r--r--app.js77
1 files changed, 37 insertions, 40 deletions
diff --git a/app.js b/app.js
index 31609a0..b206cb1 100644
--- a/app.js
+++ b/app.js
@@ -25,6 +25,12 @@ const mime = {
mp4: 'video/mp4',
webm: 'video/webm'
}
+const assets = [
+ 'js',
+ 'css',
+ 'img',
+ 'vid'
+]
require('dotenv').config()
// Handles the routes
@@ -45,23 +51,6 @@ class App {
}))
}
- app.get('/js/*', this.#Logger, (req, res) => {
- const data = this.readfile.GetFile(req.path)
- data.mime.then(output => this.#FileOpen({data: data, mime: output, res: res}))
- })
- app.get('/css/*', this.#Logger, (req, res) => {
- const data = this.readfile.GetFile(req.path)
- data.mime.then(output => this.#FileOpen({data: data, mime: output, res: res}))
- })
- app.get('/img/*', this.#Logger, (req, res) => {
- const data = this.readfile.GetFile(req.path)
- data.mime.then(output => this.#FileOpen({data: data, mime: output, res: res}))
- })
- app.get('/vid/*', this.#Logger, (req, res) => {
- const data = this.readfile.GetFile(req.path)
- data.mime.then(output => this.#FileOpen({data: data, mime: output, res: res}))
- })
-
app.route('*')
.get(this.#ValidateCookie, this.#Logger, (req, res) => {
this.controller.Main().then(output => {
@@ -70,27 +59,32 @@ class App {
string: req.path
}
- switch (this.path.split[1]) {
- case 'favicon.ico':
- this.data = this.readfile.GetFavicon()
- this.data.mime.then(output => this.#FileOpen({data: this.data, mime: output, res: res}))
- break
- case 'robots.txt':
- this.data = this.readfile.GetRobots()
- this.data.mime.then(output => this.#FileOpen({data: this.data, mime: output, res: res}))
- break
- default:
- if (this.path.string.endsWith('/') && this.path.string.length > 1) this.path.string = this.path.string.substring(0, this.path.string.length - 1)
- if (output.has(this.path.string)) {
- try {
- output.get(this.path.string).then(output => res.send(this.readfile.GetMain(output.meta)))
- } catch {
- res.send(this.readfile.GetMain(output.get(this.path.string)))
+ if (assets.includes(this.path.split[1])) {
+ const data = this.readfile.GetFile(req.path)
+ data.mime.then(output => this.#FileOpen({data: data, mime: output, res: res}))
+ } else {
+ switch (this.path.split[1]) {
+ case 'favicon.ico':
+ this.data = this.readfile.GetFavicon()
+ this.data.mime.then(output => this.#FileOpen({data: this.data, mime: output, res: res}))
+ break
+ case 'robots.txt':
+ this.data = this.readfile.GetRobots()
+ this.data.mime.then(output => this.#FileOpen({data: this.data, mime: output, res: res}))
+ break
+ default:
+ if (this.path.string.endsWith('/') && this.path.string.length > 1) this.path.string = this.path.string.substring(0, this.path.string.length - 1)
+ if (output.has(this.path.string)) {
+ try {
+ output.get(this.path.string).then(output => res.send(this.readfile.GetMain(output.meta)))
+ } catch {
+ res.send(this.readfile.GetMain(output.get(this.path.string)))
+ }
+ } else {
+ res.sendStatus(404)
}
- } else {
- res.sendStatus(404)
- }
- break
+ break
+ }
}
})
})
@@ -103,14 +97,15 @@ class App {
if (this.path.string.endsWith('/') && this.path.string.length > 1) this.path.string = this.path.string.substring(0, this.path.string.length - 1)
this.controller.Main(req.body.value).then(output => {
if (output.has(this.path.string)) {
- const data = this.readfile.Create(output.get(this.path.string))
try {
output.get(this.path.string).then(output => {
const object = this.readfile.Create(output.html)
const window = new JSDOM('').window
const DOMPurify = createDOMPurify(window)
object.then(output => {
- const clean = DOMPurify.sanitize(output.layouts.header + output.layouts.data + output.layouts.footer, { ADD_TAGS: ["iframe"], ADD_ATTR: ['allow', 'allowfullscreen', 'frameborder', 'scrolling'] })
+ const clean = DOMPurify.sanitize(output.layouts.header + output.layouts.data + output.layouts.footer, {
+ ADD_TAGS: ["iframe"], ADD_ATTR: ['allow', 'allowfullscreen', 'frameborder', 'scrolling']
+ })
res.send(clean)
})
})
@@ -119,7 +114,9 @@ class App {
const window = new JSDOM('').window
const DOMPurify = createDOMPurify(window)
object.then(output => {
- const clean = DOMPurify.sanitize(output.layouts.header + output.layouts.data + output.layouts.footer, { ADD_TAGS: ['iframe'], ADD_ATTR: ['allow', 'allowfullscreen', 'frameborder', 'scrolling'] })
+ const clean = DOMPurify.sanitize(output.layouts.header + output.layouts.data + output.layouts.footer, {
+ ADD_TAGS: ['iframe'], ADD_ATTR: ['allow', 'allowfullscreen', 'frameborder', 'scrolling']
+ })
res.send(clean)
})
}