我可以为子应用程序使用透明路由吗?

时间:2013-11-23 15:14:42

标签: node.js express

Express要求子应用程序定义绝对路由。 我不能只使用'/'中的otherApp来匹配所有app路径。{/ p>

var app = express();
var otherApp = express();

app.get('/', function (req, res) {
    res.send('HELLO!');
});

//this works
otherApp.get('/other', function (req, res) {
    res.send(req.path);
});

//this doesn't
otherApp.get('/', function (req, res) {
    res.send(req.path);
});

app.get('/other*', otherApp);

如果我想将路线更改为otherApp,我也必须在子应用程序中更改它。

有没有办法为所有子应用程序透明地/相对地定义?

1 个答案:

答案 0 :(得分:1)

试试app.use('/other/', otherApp);。请注意它是use而不是get