Skip to content

Commit e42d103

Browse files
authored
Merge pull request #1816 from payloadcms/feat/prebuilt-config
feat: allows init to accept a pre-built config
2 parents 5a7972f + 84e00bf commit e42d103

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/config/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export type InitOptions = {
108108
* See Pino Docs for options: https://getpino.io/#/docs/api?id=options
109109
*/
110110
loggerOptions?: LoggerOptions;
111+
config?: SanitizedConfig
111112
};
112113

113114
/**

src/init.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable no-param-reassign */
22
import express, { NextFunction, Response } from 'express';
33
import crypto from 'crypto';
4+
import path from 'path';
45
import mongoose from 'mongoose';
56
import { InitOptions } from './config/types';
67

@@ -30,6 +31,7 @@ import Logger from './utilities/logger';
3031
import { getDataLoader } from './collections/dataloader';
3132
import mountEndpoints from './express/mountEndpoints';
3233
import PreferencesModel from './preferences/model';
34+
import findConfig from './config/find';
3335

3436
export const init = (payload: Payload, options: InitOptions): void => {
3537
payload.logger.info('Starting Payload...');
@@ -52,7 +54,21 @@ export const init = (payload: Payload, options: InitOptions): void => {
5254

5355
payload.local = options.local;
5456

55-
payload.config = loadConfig(payload.logger);
57+
if (options.config) {
58+
payload.config = options.config;
59+
const configPath = findConfig();
60+
61+
payload.config = {
62+
...options.config,
63+
paths: {
64+
configDir: path.dirname(configPath),
65+
config: configPath,
66+
rawConfig: configPath,
67+
},
68+
};
69+
} else {
70+
payload.config = loadConfig(payload.logger);
71+
}
5672

5773
// If not initializing locally, scaffold router
5874
if (!payload.local) {

0 commit comments

Comments
 (0)