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,我也必须在子应用程序中更改它。
有没有办法为所有子应用程序透明地/相对地定义?
答案 0 :(得分:1)
试试app.use('/other/', otherApp);
。请注意它是use
而不是get
。