feat: verbose request output

This commit is contained in:
Joe Fleming
2021-07-23 15:35:34 -07:00
parent bfe452f820
commit f19e9fe356

View File

@@ -1,18 +1,27 @@
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,
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}`);
});