uses config path approach similar to NextJS
This commit is contained in:
@@ -6,7 +6,7 @@ const { email, password } = require('../tests/credentials');
|
||||
* @jest-environment node
|
||||
*/
|
||||
|
||||
const config = require('../../demo/payload.public.config');
|
||||
const config = require('../../demo/payload.config');
|
||||
|
||||
const url = config.serverURL;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
require('isomorphic-fetch');
|
||||
const faker = require('faker');
|
||||
const config = require('../../../demo/payload.public.config');
|
||||
const config = require('../../../demo/payload.config');
|
||||
const { email, password } = require('../../tests/credentials');
|
||||
|
||||
const url = config.serverURL;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require('isomorphic-fetch');
|
||||
const server = require('../../demo/server');
|
||||
const config = require('../../demo/payload.public.config');
|
||||
const config = require('../../demo/payload.config');
|
||||
const { email, password } = require('./credentials');
|
||||
|
||||
const url = config.serverURL;
|
||||
|
||||
@@ -1,17 +1,41 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
/* eslint-disable import/no-dynamic-require */
|
||||
/* eslint-disable global-require */
|
||||
|
||||
const getConfig = (options) => {
|
||||
if (!options.config || !options.config.public || !options.config.private) {
|
||||
throw new Error('Error: missing config paths. Please specify where to find your configuration files while initializing Payload.');
|
||||
const getConfig = (options = {}) => {
|
||||
if (!options.secret) {
|
||||
throw new Error('Error: missing secret key. A secret key is needed to secure Payload.');
|
||||
}
|
||||
|
||||
const publicConfig = require(options.config.public);
|
||||
const privateConfig = require(options.config.private);
|
||||
if (!options.mongoURL) {
|
||||
throw new Error('Error: missing MongoDB connection URL.');
|
||||
}
|
||||
|
||||
let configPath = path.resolve(__dirname, '../../../payload.config.js');
|
||||
|
||||
if (!fs.existsSync(configPath)) {
|
||||
if (typeof options.config !== 'string') {
|
||||
throw new Error('Error: cannot find Payload config. Please create a configuration file located at the root of your project called "payload.config.js".');
|
||||
}
|
||||
|
||||
if (fs.existsSync(options.config)) {
|
||||
configPath = options.config;
|
||||
}
|
||||
}
|
||||
|
||||
const publicConfig = require(configPath);
|
||||
|
||||
return {
|
||||
...publicConfig,
|
||||
...privateConfig,
|
||||
secret: options.secret,
|
||||
mongoURL: options.mongoURL,
|
||||
email: options.email,
|
||||
paths: {
|
||||
...publicConfig.paths,
|
||||
config: configPath,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ module.exports = (config) => {
|
||||
resolve: {
|
||||
modules: ['node_modules', path.resolve(__dirname, '../../node_modules')],
|
||||
alias: {
|
||||
'payload/unsanitizedConfig': config.paths.publicConfig,
|
||||
'payload/unsanitizedConfig': config.paths.config,
|
||||
'payload/config': path.resolve(__dirname, '../client/config.js'),
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user