const express = require("express");
const app = express();
const bodyParser = require("body-parser");
const port = 3000;
app.all("*", function(_, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Content-Type");
res.header("Access-Control-Allow-Methods", "*");
res.header("Content-Type", "application/json;charset=utf-8");
next();
});
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json({ type: "application/*+json" }));
app.get("/", (_, res) => res.send("Hello World!"));
app.post("*", function(req, res) {
console.log(req.body);
res.json(req.body);
});
app.listen(port, () => console.log(`Web 服务器正运行在 ${port} 端口!`));