Skip to content

Commit

Permalink
Add a build flag to enable the trailingSlash option for Next (#807)
Browse files Browse the repository at this point in the history
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 /.
  • Loading branch information
bpierre authored Jan 31, 2025
1 parent d3ec4d5 commit 0d9ccda
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions INSTRUCTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions frontend/app/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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";
}

0 comments on commit 0d9ccda

Please sign in to comment.