我正在尝试使摩根对人体产生反应,这是我的代码:
morgan.token('request-body', (req, res) => {
return res.body && (res.body && `\n## RESPONSE ## ${JSON.stringify(req.body)}\n` || "{}\n")
});
app.use(morgan(':request-body'));
但总是这样,身体反应是空的
这是我的app.js
var bodyParser = require('body-parser')
var morgan = require('morgan')
app.use(bodyParser.json())
app.use(morgan())
谢谢
答案 0 :(得分:1)
尝试使用morgan-body
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);
答案 1 :(得分:0)
您可以尝试:app.use(morgan('combined'))