2014-01-07 78 views

回答

5

肯定的:

var express = require('express'); 

var main = express(); 
var app1 = express(); 
var app2 = express(); 

main.use(app1); 
main.use(app2); 

app1.get('/app1/test', function(req, res) { 
    res.send('handled by app1'); 
}); 

app2.get('/app2/test', function(req, res) { 
    res.send('handled by app2'); 
}); 

main.listen(3012); 

如果每個應用程序都有自己獨特的URL前綴,你也可以使用這個:

var express = require('express'); 

var main = express(); 
var app1 = express(); 
var app2 = express(); 

main.use('/app1', app1); 
main.use('/app2', app2); 

app1.get('/test', function(req, res) { // GET /app1/test 
    res.send('handled by app1'); 
}); 

app2.get('/test', function(req, res) { // GET /app2/test 
    res.send('handled by app2'); 
}); 

main.listen(3012); 
相關問題