Skip to content

Commit

Permalink
Merge pull request #82 from IPRIT/patch-1
Browse files Browse the repository at this point in the history
Bug fixes and minor improvements
  • Loading branch information
knopki authored May 19, 2020
2 parents 964501e + ea16227 commit b92dc8d
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions modules/@amperka/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -23,22 +22,25 @@ 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('<h1>404 - Not found</h1>');
}
res.end();
};

exports.create = function() {
Expand Down

0 comments on commit b92dc8d

Please sign in to comment.