Skip to content

Commit

Permalink
ok, corrected put issue
Browse files Browse the repository at this point in the history
  • Loading branch information
pxai committed Mar 28, 2018
1 parent 46abf16 commit f9925c4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
11 changes: 4 additions & 7 deletions miniapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,12 @@ class Miniapi {
}

start () {
this.server = http.createServer((req, res) => {

let url = req.url.split("/");//;req.url.match(/\/(.*)\/(.*)/);
requestHandler.setData(this.data);
requestHandler.setName(this.name);

log.warn(req.url + ", "+ url[0]+", " + url[1])
requestHandler.setData(this.data);
requestHandler.setName(this.name);
this.server = http.createServer((req, res) => {
let url = req.url.split("/");
res.setHeader('Content-Type', this.contentType);

if (req.method === 'POST' || req.method === 'PUT') {
var body = '';
var self = this;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "miniapi",
"version": "1.0.9",
"version": "1.0.10",
"description": "Minimalistic api server",
"main": "index.js",
"scripts": {
Expand Down
8 changes: 4 additions & 4 deletions requestHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class RequestHandler {
res.statusCode = data.id==undefined?404:200;
}
res.data = data;
log.byCode(`GET ${res.statusCode} ${url}`, res.statusCode);
log.byCode(`🌐 GET ${res.statusCode} ${url}`, res.statusCode);
return res;
}

Expand All @@ -49,7 +49,7 @@ class RequestHandler {
res.statusCode = 404;
}
res.data = data;
log.byCode(`POST ${res.statusCode} ${url}`, res.statusCode);
log.byCode(`POST ${res.statusCode} ${url}`, res.statusCode);
return res;
}

Expand All @@ -65,7 +65,7 @@ class RequestHandler {
res.statusCode = data.id==undefined?404:200;;
}
res.data = data;
log.byCode(`DELETE ${res.statusCode} ${url}`, res.statusCode);
log.byCode(`DELETE ${res.statusCode} ${url}`, res.statusCode);
return res;
}

Expand All @@ -84,7 +84,7 @@ class RequestHandler {
res.statusCode = data.id==undefined?404:200;
}
res.data = data;
log.byCode(`PUT ${res.statusCode} ${url}`, res.statusCode);
log.byCode(`📝 PUT ${res.statusCode} ${url}`, res.statusCode);
return res;
}

Expand Down

0 comments on commit f9925c4

Please sign in to comment.