Skip to content

Commit 7c094dc

Browse files
authored
docs: building without a db connection (#12607)
Closes #12605 Adds documentation for one of the most common problems - building a site without a database connection (and why Payload may even need that).
1 parent c83e791 commit 7c094dc

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
title: Building without a DB connection
3+
label: Building without a DB connection
4+
order: 10
5+
desc: You don't want to have a DB connection while building your Docker container? Learn how to prevent that!
6+
keywords: deployment, production, config, configuration, documentation, Content Management System, cms, headless, javascript, node, react, nextjs
7+
---
8+
9+
# Building without a DB connection
10+
11+
One of the most common problems when building a site for production, especially with Docker - is the DB connection requirement.
12+
13+
The important note is that Payload by itself does not have this requirement, But [Next.js' SSG ](https://nextjs.org/docs/pages/building-your-application/rendering/static-site-generation) does if any of your route segments have SSG enabled (which is default, unless you opted out or used a [Dynamic API](https://nextjs.org/docs/app/deep-dive/caching#dynamic-apis)) and use the Payload Local API.
14+
15+
Solutions:
16+
17+
## Using the experimental-build-mode Next.js build flag
18+
19+
You can run Next.js build using the `pnpx next build --experimental-build mode compile` command to only compile the code without static generation, which does not require a DB connection. In that case, your pages will be rendered dynamically, but after that, you can still generate static pages using the `pnpx next build --experimental-build mode generate` command when you have a DB connection.
20+
21+
[Next.js documentation](https://nextjs.org/docs/pages/api-reference/cli/next#next-build-options)
22+
23+
## Opting-out of SSG
24+
25+
You can opt out of SSG by adding this all the route segment files:
26+
27+
```ts
28+
export const dynamic = 'force-dynamic'
29+
```
30+
31+
**Note that it will disable static optimization and your site will be slower**.
32+
More on [Next.js documentation](https://nextjs.org/docs/app/deep-dive/caching#opting-out-2)

docs/production/deployment.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ Follow the docs to configure any one of these storage providers. For local devel
150150
## Docker
151151

152152
This is an example of a multi-stage docker build of Payload for production. Ensure you are setting your environment
153-
variables on deployment, like `PAYLOAD_SECRET`, `PAYLOAD_CONFIG_PATH`, and `DATABASE_URI` if needed.
153+
variables on deployment, like `PAYLOAD_SECRET`, `PAYLOAD_CONFIG_PATH`, and `DATABASE_URI` if needed. If you don't want to have a DB connection and your build requires that, learn [here](./building-without-a-db-connection) how to prevent that.
154154

155155
In your Next.js config, set the `output` property `standalone`.
156156

0 commit comments

Comments
 (0)