2016-03-20 30 views
0

我想在iis的子路由中託管我的nodejs服務器應用程序。我想要做的就是託管我的應用程序,例如localhost:3000/node/not localhost:3000 /。 這可以通過Nodejs - 託管子網路

改變端點從

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

來實現

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

,但我不希望每次我改變我的託管路徑的時間來改變所有的API端點。

另一個是

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); 
}); 

但這看起來並不像一個適當的方式來實現這一目標。請指引我走向正確的方向。謝謝。

回答

0

你可以只在/node安裝路由器,只需添加所有的路線到路由器來代替:

// 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);