const express = require('express');
const app = express();
const bodyParser = require('body-parser');
//拦截所有请求
//extends:true 方法内部使用第三方模块请求的参数
app.use(fn({ a: 1 }));
function fn(obj) {
return function(req, res, next) {
if (obj.a == 1) {
console.log(req.url);
} else {
console.log(req.method)
}
next();
}
}
app.get('/', (req, res) => {
res.send('ok');
})
app.listen(3000);
console.log('服务器启动成功');