Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes and minor improvements #82

Merged
merged 3 commits into from
May 19, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 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,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);
};

IPRIT marked this conversation as resolved.
Show resolved Hide resolved
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>');
}

IPRIT marked this conversation as resolved.
Show resolved Hide resolved
res.end();
};

exports.create = function() {
Expand Down