paritybit.ca

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

commit d4740de415aeb454a0076620e472d9288625b1bc
parent ba58ecd5821663b1abd0672964a0569067203474
Author: Jake Bauer <jbauer@paritybit.ca>
Date:   Sun, 14 Apr 2019 19:39:13 -0400

Remove unnecessary error checking and add logging for errors

Diffstat:
Mserver/app.js | 28+++++++++++++---------------
1 file changed, 13 insertions(+), 15 deletions(-)

diff --git a/server/app.js b/server/app.js @@ -56,6 +56,9 @@ function handle_error(err, res) { res.end(content, "utf-8"); }); } + else if (err) { + console.log(err); + } else { // If there is any other error, report error 500 res.writeHead(500, {"Content-Type": "text/plain"}); @@ -73,23 +76,18 @@ function compute_etag(content) { function serve_regular_file(filePath, contentType, req, res) { fs.readFile(filePath, (err, content) => { - if (err) { - handle_error(err, res); + let etag = compute_etag(content); + // If the resource is cached, send code 304 and don't send resource + if (etag === req.headers["if-none-match"]) { + res.writeHead(304, {"Content-Type": contentType, + "Cache-Control": "max-age=120", "ETag": etag }); + res.end(); } else { - let etag = compute_etag(content); - // If the resource is cached, send code 304 and don't send resource - if (etag === req.headers["if-none-match"]) { - res.writeHead(304, {"Content-Type": contentType, - "Cache-Control": "max-age=120", "ETag": etag }); - res.end(); - } - else { - // Otherwise, send the file - res.writeHead(200, {"Content-Type": contentType, - "Cache-Control": "max-age=120", "ETag": etag}); - res.end(content, "utf-8"); - } + // Otherwise, send the file + res.writeHead(200, {"Content-Type": contentType, + "Cache-Control": "max-age=120", "ETag": etag}); + res.end(content, "utf-8"); } }); }