节点/快递:添加中间件路由器不加载
我的路由器是这样的:
app.get('/getReport', (req, res) => {
res.send("This is the report");
});
上述路由器工作正常,并在浏览器加载,This is the report
但是当我这样做:
// Filename: router.js
const getReport = require('./getReportController');
app.get('/getReport', (req, res) => {
getReport.initial
});
和
// Filename: getReportController.js
exports.initial = (req, res) => {
res.send("This is the report");
};
它不工作,继续等待......
什么可能出了错?我的目标是调用控制器组件,然后将其添加到路由器终点。这里将是middleware
我将添加这一次解决。
我相信你想要的是:
app.get('/getReport', getReport.initial);
你只是读功能中的功能块,你正在做的方式。