From e0d1f50710b85971cbdaaf6be4420acb401b6a7f Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Fri, 23 Jul 2021 15:35:34 -0700 Subject: [PATCH] feat: verbose request output --- src/index.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/index.js b/src/index.js index 22f1865..eed1693 100644 --- a/src/index.js +++ b/src/index.js @@ -1,18 +1,28 @@ const express = require('express'); const cors = require('cors'); +const PORT = process.env.PORT || 8080; + const app = express(); app.use(cors()); -app.use(express.urlencoded({ extended: false })); app.use(express.json()); +app.use(express.urlencoded({ extended: false })); app.use(function (req, res) { - res.setHeader('Content-Type', 'text/plain'); - res.write('you posted:\n'); - res.end(JSON.stringify(req.body, null, 2)); + const info = { + method: req.method, + url: req.url, + headers: req.headers, + body: req.body, + }; + console.log(info); + + res.setHeader('Content-Type', 'application/plain'); + res.write(JSON.stringify(info, null, 2)); + res.end(); }); -app.listen(80, function () { - console.log('CORS-enabled web server listening on port 80'); +app.listen(PORT, function () { + console.log(`CORS-enabled web server listening on port ${PORT}`); });