小编use*_*710的帖子

在Express NodeJS中调用其他路由中已定义的路由

我正在使用Express在node.js中编写一个Web应用程序.我已经定义了如下路线:

app.get("/firstService/:query", function(req,res){
    //trivial example
    var html = "<html><body></body></html>"; 
    res.end(html)
});
Run Code Online (Sandbox Code Playgroud)

如何从快递中重用该路线?

app.get("/secondService/:query", function(req,res){
    var data = app.call("/firstService/"+query);
    //do something with the data
    res.end(data);
});
Run Code Online (Sandbox Code Playgroud)

我在API文档中找不到任何内容,宁愿不使用像"请求"这样的其他库,因为这看起来很笨拙.我想尽可能保持我的应用程序模块化.思考?

谢谢

node.js express run-middleware

30
推荐指数
2
解决办法
3万
查看次数

标签 统计

express ×1

node.js ×1

run-middleware ×1