diff options
-rw-r--r-- | app/lib/router.js | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/app/lib/router.js b/app/lib/router.js index 8c0a2ef..fd24693 100644 --- a/app/lib/router.js +++ b/app/lib/router.js @@ -27,9 +27,22 @@ class Router { }; } - gpost(re, cb, max) { // Laziness + gpost(re, cb, max) { this.post(re, this.gather(cb, max)); } + + jpost(re, cb, max) { + this.gpost(re, (req, res, match, data) => { + try { + data = JSON.parse(data); + } catch (e) { + res.writeHead(400, {"Content-Type": "text/plain"}); + return res.end("400 Bad Request"); + } + + cb(req, res, match, data); + }, max); + } } ["get", "post", "put", "delete"].forEach(method => |