paritybit.ca

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 7e598a33c004390c8999e6d27906530461549291
parent 189aa891ce9a00b2ccd4cdcecb1c22eef2063fa4
Author: Jake Bauer <jbauer@paritybit.ca>
Date:   Tue,  7 May 2019 18:39:51 -0400

Add contentType exception for sitemap.xml and ability to serve pages even if .html not specified

Diffstat:
Mserver/app.js | 11+++++++++++
1 file changed, 11 insertions(+), 0 deletions(-)

diff --git a/server/app.js b/server/app.js @@ -120,6 +120,7 @@ const httpServer = http.createServer((req, res) => { '.js': 'text/javascript', '.css': 'text/css', '.txt': 'text/plain', + '.xml': 'application/rss+xml', '.json': 'application/json', '.svg': 'application/image/svg+xml', '.png': 'image/png', @@ -139,7 +140,17 @@ const httpServer = http.createServer((req, res) => { // Get the extension of the file requested and therefore the content type let extName = String(path.extname(req.url)).toLowerCase(); + // If url does not specify a file extension then assume html file requested + console.log(extName); + if (extName === "") { + extName = ".html"; + req.url += ".html"; + } let contentType = mimeTypes[extName] || "application/octet-stream"; + // Make contentType exception for sitemap.xml file (everything else is RSS) + if (req.url === "/sitemap.xml") { + contentType = "application/xml"; + } // Append html directory for serving pages (other resources will be // addressed directly as (e.g.) "/css/base.min.css")