繁体   English   中英

节点/ Express:将中间件添加到路由器不会加载

[英]Node/Express: Adding middleware to router does not load

我的路由器如下所示:

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);

您只是在按照自己的方式读取功能块中的功能。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM