Initial commit

This commit is contained in:
Daniel Kluge 2022-05-16 16:14:00 +02:00
commit 3f3353407d
4 changed files with 1068 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules

27
index.mjs Normal file
View File

@ -0,0 +1,27 @@
import express from "express";
import bodyParser from "body-parser";
const app = express()
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(bodyParser.text());
const port = Number.parseInt(process.env.PORT) || 8080;
// Express route that prints request body and query parameters
app.all("*", (req, res) => {
console.log("------------------------------");
console.log(`New HTTP ${req.method} Request to ${req.path}`);
console.log(`Headers:\n${JSON.stringify(req.headers, null, 2)}`);
if (req.query && Object.keys(req.query).length > 0) console.log(`Query Parameters:\n${JSON.stringify(req.query, null, 2)}`);
if (req.body && Object.keys(req.body).length > 0) {
try {
console.log(`Body Parameters:\n${JSON.stringify(req.body, null, 2)}`);
} catch {
console.log(`Body Parameters:\n${req.body}`);
}
}
res.status(204).end();
});
app.listen(port, () => console.log(`Callback server listening on port ${port}!`));

1019
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

21
package.json Normal file
View File

@ -0,0 +1,21 @@
{
"name": "simple-callback-server",
"version": "1.0.0",
"description": "A simple server that prints headers and body of a request to the console.",
"main": "index.mjs",
"scripts": {
"start": "node index.mjs",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"server",
"simple",
"http"
],
"author": "Daniel Kluge",
"license": "MIT",
"dependencies": {
"body-parser": "^1.20.0",
"express": "^4.18.1"
}
}