From 2cbf0a5c5dc4f66597b1c358b2182d08d17c6755 Mon Sep 17 00:00:00 2001 From: nyeoro-bong <68091561+nyeoro-bong@users.noreply.github.com> Date: Sun, 3 Oct 2021 12:14:46 +0900 Subject: [PATCH] =?UTF-8?q?DELETE=E3=83=AA=E3=82=AF=E3=82=A8=E3=82=B9?= =?UTF-8?q?=E3=83=88=E8=A1=A8=E7=A4=BA=E3=81=AE=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 3365883..a6f7dd7 100644 --- a/index.js +++ b/index.js @@ -2,13 +2,35 @@ const http = require('http'); const server = http .createServer((req, res) => { + const now = new Date(); console.info( - '[' + new Date() + '] Requested by ' + req.socket.remoteAddress + '[' + now + '] Requested by ' + req.socket.remoteAddress ); res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' }); - res.write(req.headers['user-agent']); + + switch (req.method) { + case 'GET': + res.write('GET' + req.url); + break; + case 'POST': + res.write('POST' + req.url); + let rawData = ''; + req + .on('data', chunk => { + rawData = rawData + chunk; + }) + .on('end', () => { + console.info('[' + now + '] Data posted: ' + rawData); + }); + break; + case 'DELETE': + res.write('DELETE' + req.url); + break; + default: + break; + } res.end(); }) .on('error', e => {