2016-03-20 5 views
0

iisのサブルートにnodejsサーバーアプリケーションをホストしたいとします。私がしたいのは、localhost:3000/node/not localhost:3000 /のように私のアプリケーションをホストすることです。 これはNodejs - サブルーティングするホスト

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

app.get('/', moduleRoutes.root); 
app.post('/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); 
関連する問題