Compare commits

...

2 Commits

Author SHA1 Message Date
James Mikrut
e8366f08fb chore: removes incorrect type additions 2025-05-06 13:08:15 -05:00
James Mikrut
77de96c222 feat: allows for functional config definitions 2025-05-06 13:03:17 -05:00
2 changed files with 26 additions and 2 deletions

View File

@@ -27,6 +27,26 @@ The Payload Config is strongly typed and ties directly into Payload's TypeScript
details](#customizing-the-config-location).
</Banner>
#### Functionally building your config
You can optionally pass a function to `buildConfig` which is helpful if you need to first fetch secrets or define how you want Payload to work prior to initializing it.
Here's an example:
```ts
import { buildConfig } from 'payload'
import { fetchMySecrets } from './secrets'
export default buildConfig(async () => {
const mySecrets = await fetchMySecrets()
return {
secret: mySecrets.PAYLOAD_SECRET,
// The rest of your config goes here
}
})
```
## Config Options
To author your Payload Config, first determine which [Database](../database/overview) you'd like to use, then use [Collections](./collections) or [Globals](./globals) to define the schema of your data through [Fields](../fields/overview).

View File

@@ -4,10 +4,14 @@ import { sanitizeConfig } from './sanitize.js'
/**
* @description Builds and validates Payload configuration
* @param config Payload Config
* @param config Payload Config or async function that returns a Config
* @returns Built and sanitized Payload Config
*/
export async function buildConfig(config: Config): Promise<SanitizedConfig> {
export async function buildConfig(
configArg: (() => Config | Promise<Config>) | Config,
): Promise<SanitizedConfig> {
const config = typeof configArg === 'function' ? await configArg() : configArg
if (Array.isArray(config.plugins)) {
let configAfterPlugins = config
for (const plugin of config.plugins) {