2016-03-20 19 views
0

ide'de bir alt rotada nodejs sunucu uygulamamı barındırmak istiyorum. Benim yapmak istediğim, bu tür bir localhost olarak uygulamamı barındırmaktır: 3000/node/localhost: 3000 /. BuNodejs - Robota abone olun

app.get('/node/', moduleRoutes.root); 
app.post('/node/auth/signup/', authenticationRoutes.signup); 

için

app.get('/', moduleRoutes.root); 
app.post('/auth/signup/', authenticationRoutes.signup); 

den

değişen uç noktalarının elde edilebilir ama tüm API bitiş benim barındırma yolunu değiştirmek her zaman değiştirmek istemiyoruz.

başka

app.use((req, res, next) => { 
    //change request location from here by changing 
    req.url = req.url.replace('localhost:3000/node/', 'localhost:3000') 
    //somthing like that 
    authorization.memberinfo(req, res, next); 
}); 

ama bu bunu başarmak için uygun bir yol gibi görünmüyor. Lütfen beni doğru yöne yönlendirin. Teşekkürler.

cevap

0

sadece /node bir yönlendirici montaj ve sadece yerine o router için tüm yolların ekleyebilirsiniz:

// These three lines could even be placed in a separate file that you 
// would `require()` and use in your app.js 
var router = express.Router(); 
router.get('/', moduleRoutes.root); 
router.post('/auth/signup/', authenticationRoutes.signup); 

app.use('/node', router);