1
0
Fork 0
mirror of https://github.com/kou029w/http-echo.git synced 2025-01-18 16:08:13 +00:00
http-echo/index.js

21 lines
530 B
JavaScript
Raw Normal View History

2020-03-24 00:52:27 +09:00
const express = require("express");
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(express.raw({ type: "*/*" }));
2020-03-24 14:12:03 +09:00
app.set("json spaces", 2);
2020-03-24 00:52:27 +09:00
app.all("/*", function(req, res) {
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);