mirror of
https://github.com/kou029w/http-echo.git
synced 2025-01-18 16:08:13 +00:00
feat: pretty response format
This commit is contained in:
parent
ba5bdc8e09
commit
201e67c4f1
1 changed files with 1 additions and 2 deletions
3
index.js
3
index.js
|
@ -4,9 +4,8 @@ const app = express();
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
app.use(express.urlencoded({ extended: false }));
|
app.use(express.urlencoded({ extended: false }));
|
||||||
app.use(express.raw({ type: "*/*" }));
|
app.use(express.raw({ type: "*/*" }));
|
||||||
|
app.set("json spaces", 2);
|
||||||
app.all("/*", function(req, res) {
|
app.all("/*", function(req, res) {
|
||||||
app.set("json spaces", req.path === "/pretty" ? 2 : null);
|
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
headers: req.headers,
|
headers: req.headers,
|
||||||
body: req.body.length > 0 ? req.body.toString() : null,
|
body: req.body.length > 0 ? req.body.toString() : null,
|
||||||
|
|
Loading…
Add table
Reference in a new issue