mirror of
https://github.com/kou029w/http-echo.git
synced 2025-01-19 00:18:07 +00:00
22 lines
565 B
JavaScript
22 lines
565 B
JavaScript
|
const express = require("express");
|
||
|
const app = express();
|
||
|
|
||
|
app.use(express.json());
|
||
|
app.use(express.urlencoded({ extended: false }));
|
||
|
app.use(express.raw({ type: "*/*" }));
|
||
|
app.all("/*", function(req, res) {
|
||
|
app.set("json spaces", req.path === "/pretty" ? 2 : null);
|
||
|
|
||
|
res.json({
|
||
|
headers: req.headers,
|
||
|
body: req.body.length > 0 ? req.body.toString() : null,
|
||
|
form: req.is("urlencoded") ? req.body : null,
|
||
|
json: req.is("json") ? req.body : null,
|
||
|
method: req.method,
|
||
|
target: req.url,
|
||
|
host: req.headers.host
|
||
|
});
|
||
|
});
|
||
|
|
||
|
app.listen(8080);
|