[英]Nodejs - Hosting to subroute
我想在iis的子路由中托管我的nodejs服務器應用程序。 我想要做的是將應用程序托管為localhost:3000 / node /而不是localhost:3000 /。 這可以通過
從改變端點
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);
});
但這似乎不是實現此目標的正確方法。 請引導我朝正確的方向。 謝謝。
您可以只在/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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.