feat: verbose request output
This commit is contained in:
21
src/index.js
21
src/index.js
@@ -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}`);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user