我试图用摩根获得身体反应,这是我的代码:
morgan.token('request-body', (req, res) => {
return res.body && (res.body && `n## RESPONSE ## ${JSON.stringify(req.body)}n` || "{}n")
});
app.use(morgan(':request-body'));
但总是,身体反应是空的
这是我的应用程序.js
var bodyParser = require('body-parser')
var morgan = require('morgan')
app.use(bodyParser.json())
app.use(morgan())
谢谢
尝试使用摩根体
import morganBody from 'morgan-body';
import express from 'express';
import bodyParser from 'body-parser';
const app = express();
// must parse body before morganBody as body will be logged
app.use(bodyParser.json());
// hook morganBody to express app
morganBody(app);
你可以试试: app.use(morgan('combined'))