![](/img/trans.png)
[英]Websocket connection to 'wss://url' failed : [vite] server connnection lost. polling for restart... after deploying the vitejs project in AWS EC2
[英]Failed to redirect route in NetxJs on AWS EC2 server
我正在 AWS EC2 服務上運行 NextJs 應用程序> 想要將具有尾部斜杠的路由重定向到非尾部斜杠路由。對於 Ex - /industry-reports/
應該路由到/industry-reports
。為此,我在服務器內部使用自定義服務器路由server.js
文件。但在本地它工作正常但在服務器上它失敗並顯示以下錯誤:
Cannot GET /industry-reports/
服務器.js
server.get('/industry-reports', async (req, res) => {
if (req.url.substring(req.url.length - 1) === '/') {
req.url = req.url.substring(0, req.url.length - 1);
return res.redirect(301, process.env.NODE_ENV === 'PRODUCTION' ? `https://www.google.com` : `https://facebook.com`)
}
const actualPage = '/industry-reports'
app.render(req, res, actualPage)
});
有人讓我知道我做錯了什么
/industry-reports/ 應該路由到 /industry-reports
NextJS 的默認行為已經是你正在嘗試做的。 您不需要自定義路由來處理尾部斜杠。 如果您只需刪除您編寫的重定向代碼,它就會起作用。
“默認情況下,Next.js 會將帶有尾部斜杠的網址重定向到沒有尾部斜杠的對應網址。”
來自: https ://nextjs.org/docs/api-reference/next.config.js/trailing-slash
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.