summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMhykol <mchaeldonald62@pm.me>2024-05-16 02:46:23 -0400
committerMhykol <mchaeldonald62@pm.me>2024-05-16 02:46:23 -0400
commit20aca1b4bba6d8dbe0b549efabcf7a01b026c63b (patch)
tree59fca4ef61d9ff3671a7e5a64f08b06496de506d
parentc23af2d13cae194be1111bbebe5233a78e972aba (diff)
Improved handling for favicon.ico and added robots.txt
-rw-r--r--app.js22
-rw-r--r--assets/img/favicon.icobin205086 -> 0 bytes
-rw-r--r--assets/robots/robots.txt2
-rw-r--r--source/readfile.js22
4 files changed, 39 insertions, 7 deletions
diff --git a/app.js b/app.js
index 74cb1f3..985e66a 100644
--- a/app.js
+++ b/app.js
@@ -19,6 +19,7 @@ const mime = {
png: 'image/png',
webp: 'image/webp',
avif: 'image/avif',
+ ico: 'image/ico',
svg: 'image/svg+xml',
js: 'application/javascript'
}
@@ -57,12 +58,21 @@ class App {
string: req.path
}
- if (this.path.split[1] === 'favicon.ico') {
- const data = this.readfile.GetFile('/img/favicon.ico')
- data.mime.then(output => this.#FileOpen({data: data, mime: output, res: res}))
- } else {
- 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)) {res.send(this.readfile.GetMain())} else {res.sendStatus(404)}
+ 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':
+ console.log('hit')
+ 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)) {res.send(this.readfile.GetMain())} else {res.sendStatus(404)}
+ break
+
}
})
})
diff --git a/assets/img/favicon.ico b/assets/img/favicon.ico
deleted file mode 100644
index f4ba292..0000000
--- a/assets/img/favicon.ico
+++ /dev/null
Binary files differ
diff --git a/assets/robots/robots.txt b/assets/robots/robots.txt
new file mode 100644
index 0000000..eb05362
--- /dev/null
+++ b/assets/robots/robots.txt
@@ -0,0 +1,2 @@
+User-agent: *
+Disallow:
diff --git a/source/readfile.js b/source/readfile.js
index 6d66210..4627781 100644
--- a/source/readfile.js
+++ b/source/readfile.js
@@ -77,7 +77,27 @@ class ReadFile {
}),
mime: this.#GetFileType(path).then(output => {return output})
}
- if (object.file) {return object} else {return false}
+ if (object.file) {return object} else {return null}
+ }
+ GetFavicon() {
+ const object = {
+ file: fs.createReadStream(`./assets/favicon/favicon.ico`).on('error', (err) => {
+ logger.Error(`${err.code}: Failed to get 'favicon.ico'`)
+ return null
+ }),
+ mime: this.#GetFileType('favicon.ico')
+ }
+ if (object.file) {return object} else {return null}
+ }
+ GetRobots() {
+ const object = {
+ file: fs.createReadStream(`./assets/robots/robots.txt`).on('error', (err) => {
+ logger.Error(`${err.code}: Failed to get 'robots.txt'`)
+ return null
+ }),
+ mime: this.#GetFileType('robots.txt')
+ }
+ if (object.file) {return object} else {return null}
}
CreateBlog(x) {
const data = {