2017-02-21 36 views

回答

1

您可以使用快速的正則表達式匹配的路由。

app.get(/appID-appspot.com/, function (req, res) { 
    res.redirect('custom_domain'); 
} 

/appID-appspot.com/

匹配url和重定向到customdomain,如果URL中包含的一部分。

將上述內容添加到路由的頂部,以便首先重定向。

+0

我相信這是正確的答案,但遺憾的是,它並沒有幫助我的情況,似乎重定向是在我的應用程序代碼被調用之前進行操作的。 – Coder1000

+0

做了一件事,測試這個代碼,'app.get(/appID-appspot.com/,function(req,res){res.send('custom_domain'); }'並檢查它何時被調用 – Sravan

+0

我怎樣才能檢查它是什麼時候被調用的? – Coder1000

0

您應該使用res.redirect(301, 'http://example.com');

完整的示例:

router.get('/', function(req, res){ 
    res.redirect(301, 'custom domain'); 
}); 
相關問題