fix: default to .env (#40315)
This commit is contained in:
committed by
GitHub
parent
df44da9dc2
commit
ebb4e0d5cc
@ -1,13 +1,11 @@
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
if (process.env.FREECODECAMP_NODE_ENV !== 'production') {
|
const envPath = path.resolve(__dirname, '../.env');
|
||||||
const envPath = path.resolve(__dirname, '../.env');
|
if (!fs.existsSync(envPath)) {
|
||||||
if (!fs.existsSync(envPath)) {
|
throw Error('.env not found, please copy sample.env to .env.');
|
||||||
throw Error('.env not found, please copy sample.env to .env.');
|
|
||||||
}
|
|
||||||
require('dotenv').config({ path: envPath });
|
|
||||||
}
|
}
|
||||||
|
require('dotenv').config({ path: envPath });
|
||||||
|
|
||||||
const {
|
const {
|
||||||
HOME_LOCATION: home,
|
HOME_LOCATION: home,
|
||||||
|
@ -1,14 +1,17 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const debug = require('debug');
|
||||||
|
|
||||||
const env = require('../../../config/env');
|
const env = require('../../../config/env');
|
||||||
|
|
||||||
|
const log = debug('fcc:ensure-env');
|
||||||
|
|
||||||
const clientPath = path.resolve(__dirname, '../../../client');
|
const clientPath = path.resolve(__dirname, '../../../client');
|
||||||
const globalConfigPath = path.resolve(__dirname, '../../../config');
|
const globalConfigPath = path.resolve(__dirname, '../../../config');
|
||||||
|
|
||||||
const { FREECODECAMP_NODE_ENV } = process.env;
|
const { FREECODECAMP_NODE_ENV } = process.env;
|
||||||
|
|
||||||
if (FREECODECAMP_NODE_ENV === 'production') {
|
if (FREECODECAMP_NODE_ENV !== 'development') {
|
||||||
const locationKeys = [
|
const locationKeys = [
|
||||||
'homeLocation',
|
'homeLocation',
|
||||||
'apiLocation',
|
'apiLocation',
|
||||||
@ -51,6 +54,8 @@ if (FREECODECAMP_NODE_ENV === 'production') {
|
|||||||
|
|
||||||
if (env['showUpcomingChanges'])
|
if (env['showUpcomingChanges'])
|
||||||
throw Error("SHOW_UPCOMING_CHANGES should never be 'true' in production");
|
throw Error("SHOW_UPCOMING_CHANGES should never be 'true' in production");
|
||||||
|
} else {
|
||||||
|
log('Skipping environment variable checks in development');
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.writeFileSync(`${clientPath}/config/env.json`, JSON.stringify(env));
|
fs.writeFileSync(`${clientPath}/config/env.json`, JSON.stringify(env));
|
||||||
|
Reference in New Issue
Block a user