最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

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

IT培训 admin 4浏览 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);

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

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

我的路由器是这样的:

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. 暂无评论