2016-03-20 32 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);