私は非常に奇妙な問題に直面しています。私は2つのルートを設定しました。 1つはダッシュボード用、もう1つは外部API用です。ノードエクスプレスルートの問題
dashboard = require('./routes/dashboard')(passport);
api = require('./routes/api');
app.use('/', dashboard);
app.use('/api', api);
次の2つのルートは、api.jsルートファイルで定義されています。
router.post('/somepostlink',function(){
// this is reachable from request query.
})
router.get('/somegetlink',function(){
// this is NOT reachable from request query.
})
私はこれが私のdashboard.jsルートファイルで定義されている:
何のルートが一致していない場合、コントロールは今
router.get('*',function (request,response) {
console.log("Route not found");
return response.send("OOPs :(\nSeems like the page you are looking
for, isn't available with us.").status(404);
、の下のコードのブロックに転送される// POST localhostへのリクエスト:3000/api/somepostlinkが動作します。 しかし、ローカルホストに要求をGET:3000/API/somegetlinkは
"あなたが を探しているページのような\ nSeems :(おっと、私たちでは利用できません"
は(キャッチに 'app'があるファイル内のすべての' * 'ルートを入れて、' app.getを行います'*'、...) 'setuした後あなたのAPIとダッシュボードのルータ。 – Li357
@AndrewLi私はそれを試しましたが、それでもdashboard.jsルートファイルでそれを見つけることを試み、ダッシュボードのホームページを表示します...( '/')ルート – Nikhil