From 0d9ccdaef4a9f8e0058ca2084b17ae37bd65b20e Mon Sep 17 00:00:00 2001 From: Pierre Bertet Date: Fri, 31 Jan 2025 13:19:27 +0000 Subject: [PATCH] Add a build flag to enable the trailingSlash option for Next (#807) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This builds routes in separate directories rather than in .html files. The is useful for servers that can’t serve .html files by default. The downside is that routes get a final /. --- INSTRUCTIONS.md | 6 ++++++ frontend/app/next.config.js | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/INSTRUCTIONS.md b/INSTRUCTIONS.md index b9abeab32..e2e833fa9 100644 --- a/INSTRUCTIONS.md +++ b/INSTRUCTIONS.md @@ -63,6 +63,12 @@ pnpm build The app will be built in the `out/` directory which can be deployed to any static hosting service. +Note: your server must be configured to serve .html files by default. If you are using Vercel, this is done automatically. If your server does not support this, you can build the app with a separate directory for each route: + +```bash +NEXT_TRAILING_SLASH=1 pnpm build +``` + ## Local development setup Follow these steps to set up your local development environment: diff --git a/frontend/app/next.config.js b/frontend/app/next.config.js index 19b10902f..e9acd376a 100644 --- a/frontend/app/next.config.js +++ b/frontend/app/next.config.js @@ -23,6 +23,7 @@ export default withBundleAnalyzer({ output: "export", reactStrictMode: false, images: { unoptimized: true }, + trailingSlash: flag(process.env.NEXT_TRAILING_SLASH), env: { APP_VERSION_FROM_BUILD, APP_COMMIT_HASH_FROM_BUILD, @@ -50,3 +51,11 @@ export default withBundleAnalyzer({ ]; }, }); + +function flag(value) { + if (typeof value !== "string") { + return false; + } + value = value.trim(); + return value === "true" || value === "1" || value === "yes"; +}