我的路由器如下所示:
app.get('/getReport', (req, res) => {
res.send("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");
};
它不起作用,请继续等待...
可能出了什么问题?我的目标是调用 Controller 组件,然后将其添加到路由器端点。一旦解决这个问题,我将添加一个中间件
。
最佳答案
我相信你想要的是:
app.get('/getReport', getReport.initial);
您只是按照当前的方式读取函数 block 中的函数。
关于javascript - Node/Express : Adding middleware to router does not load,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54638577/