最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

节点快递:添加中间件路由器不加载

运维笔记admin10浏览0评论

节点/快递:添加中间件路由器不加载

节点/快递:添加中间件路由器不加载

我的路由器是这样的:

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

你只是读功能中的功能块,你正在做的方式。

发布评论

评论列表(0)

  1. 暂无评论