From 8205891102e0a8cc7a59768e870db4332755edf7 Mon Sep 17 00:00:00 2001 From: noogen Date: Sun, 25 Nov 2018 13:59:32 -0600 Subject: [PATCH] restrict to only post method --- app.js | 5 +++++ lib/response.js | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app.js b/app.js index 2c657ed..96afd9e 100644 --- a/app.js +++ b/app.js @@ -3,8 +3,13 @@ require("@babel/register") const post = require('./lib/postHandler') const http = require('http') const URL = require('url') +const resp = require('./lib/response').default http.createServer((req, res) => { + if (req.method !== 'POST') { + return resp(res, null)(`Invalid request method: ${req.method}`, 422) + } + const url = URL.parse(req.url, true) const ctype = req.headers['Content-Type'] | req.headers['content-type'] diff --git a/lib/response.js b/lib/response.js index d32eec6..97f1a67 100644 --- a/lib/response.js +++ b/lib/response.js @@ -20,7 +20,7 @@ export default (rsp, callback) => { } rsp.writeHead(code, headers || rspHeaders) - rsp.send(body) + rsp.write(body) rsp.end() } }