Look at the Nuxt 3 documentation to learn more.
Make sure to install the dependencies:
npm install
Start the development server on http://localhost:3000
:
npm run dev
Open browser then enter http://localhost:3000
curl -X POST http://localhost:3000/website-api/maintenance -H 'Content-Type: application/json'
Build the application for production:
npm run build
因為其實每次修改 .env 後,都還要重新 build 才會對新的 .env 生效。
PS. 你也可以設置好 .env 後,每次都是透過 process.env 在 server 取得,前端如果要知道,就是每次打 .env 就好。
- 在 /server/plugin 設置 Maintenance mode 初始值
(optional)
開發 Get API 供前端查詢當下狀態,但其實可以不用,因為在 Middleware 檢查到當下為 Maintenance 就應該回覆 http 503 及靜態畫面,不需要再讓前端做任何事情。- 開發 Post API 供管理員切換 Maintenance mode,記得要加上自己的驗證模式。
- 設計 Server middleware,判斷當下的 Maintenance mode 以及要請求的路徑為何,如果是要去特定在 Maintenance mode 也可以瀏覽的頁面以及 Post API 切換 Maintenance mode 的路徑都應該允許。
(optional)
設計 503 顯示畫面,將其 html 放置在 public 下。
可以參考此 repo 的 commit 6fa4e20104e0ffa88d3432082a1af9a9a415e84f,
- 可以在 plugins 增加去 Server 做 Get API 的邏輯,取得當下的 Maintenance mode。
- 在 middleware 中如果不是要及時判斷,可以使用在 1. 取得並存在 useState 中的變數判斷;如果要及時判斷,就可以透過 server middleware 判斷或者在 client middle 中每次都打 API 判斷。