From abb36fc44672ae793c5d9a5a38900527065e10b5 Mon Sep 17 00:00:00 2001 From: Alexander Belov Date: Sun, 17 May 2020 03:43:59 +0300 Subject: [PATCH 1/3] Bug fixes and minor improvements * Removed unnecessary console output; * A better `_event` function --- modules/@amperka/server.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/modules/@amperka/server.js b/modules/@amperka/server.js index eeb906c..a2bbd70 100644 --- a/modules/@amperka/server.js +++ b/modules/@amperka/server.js @@ -10,7 +10,6 @@ Server.prototype.on = function(types, callback) { types = [types]; } for (var t in types) { - console.log(t); if (!this._events[types[t]]) { this._events[types[t]] = callback; } @@ -23,22 +22,27 @@ Server.prototype.listen = function(port) { Server.prototype._onPageRequest = function(req, res) { var request = url.parse(req.url, true); - this._event(request.pathname, request, res); + this._event(request.pathname, req, res); }; Server.prototype._event = function(eventName, req, res) { + res.send = function(content, headers) { + if (headers === undefined) { + res.writeHead(200, { 'Content-Type': 'text/html' }); + } else { + res.writeHead(200, headers); + } + res.write(content); + }; + if (this._events[eventName]) { - res.send = function(content, headers) { - if (headers === undefined) { - res.writeHead(200, { 'Content-Type': 'text/html' }); - } else { - res.writeHead(200, headers); - } - res.write(content); - }; this._events[eventName](req, res); - res.end(); + } else { + res.writeHead(404, { 'Content-Type': 'text/html' }); + res.write('

404 - Not found

'); } + + res.end(); }; exports.create = function() { From 07b08ee863aeab2e77731ac8c975d2d41bd87c00 Mon Sep 17 00:00:00 2001 From: Alexander Belov Date: Tue, 19 May 2020 15:39:32 +0300 Subject: [PATCH 2/3] Trailing space Co-authored-by: Sergey Korolev --- modules/@amperka/server.js | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/@amperka/server.js b/modules/@amperka/server.js index a2bbd70..e98e8ad 100644 --- a/modules/@amperka/server.js +++ b/modules/@amperka/server.js @@ -34,7 +34,6 @@ Server.prototype._event = function(eventName, req, res) { } res.write(content); }; - if (this._events[eventName]) { this._events[eventName](req, res); } else { From ea16227f52a0a3b1391c4e97cbb3bd01210b94b6 Mon Sep 17 00:00:00 2001 From: Alexander Belov Date: Tue, 19 May 2020 15:39:41 +0300 Subject: [PATCH 3/3] Trailing space Co-authored-by: Sergey Korolev --- modules/@amperka/server.js | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/@amperka/server.js b/modules/@amperka/server.js index e98e8ad..7e6ff66 100644 --- a/modules/@amperka/server.js +++ b/modules/@amperka/server.js @@ -40,7 +40,6 @@ Server.prototype._event = function(eventName, req, res) { res.writeHead(404, { 'Content-Type': 'text/html' }); res.write('

404 - Not found

'); } - res.end(); };