Initial commit
This commit is contained in:
commit
3f3353407d
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
node_modules
|
27
index.mjs
Normal file
27
index.mjs
Normal 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
1019
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
21
package.json
Normal file
21
package.json
Normal 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"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user