From 20aca1b4bba6d8dbe0b549efabcf7a01b026c63b Mon Sep 17 00:00:00 2001 From: Mhykol Date: Thu, 16 May 2024 02:46:23 -0400 Subject: Improved handling for favicon.ico and added robots.txt --- app.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'app.js') 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 + } }) }) -- cgit v1.2.3-70-g09d2