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() } }