Commit b26a113 1 parent 4ee1a7a commit b26a113 Copy full SHA for b26a113
File tree 3 files changed +17
-11
lines changed
3 files changed +17
-11
lines changed Original file line number Diff line number Diff line change
1
+ .npmrc
Original file line number Diff line number Diff line change 1
1
let env = ( typeof window !== 'undefined' && window . env ) || { } ;
2
2
3
3
if ( typeof window === 'undefined' ) {
4
- const dotenvConfig = require ( 'dotenv' ) . config ( ) ;
5
- if ( dotenvConfig . error ) {
6
- throw dotenvConfig . error ;
7
- }
4
+ const fs = require ( 'fs' ) ;
5
+ try {
6
+ const stats = fs . statSync ( '.env' ) ;
7
+ if ( stats && stats . isFile ( ) ) {
8
+ const dotenvConfig = require ( 'dotenv' ) . config ( ) ;
9
+ if ( dotenvConfig . error ) {
10
+ throw dotenvConfig . error ;
11
+ }
8
12
9
- Object . assign ( env , dotenvConfig . parsed , process . env ) ;
13
+ Object . assign ( env , dotenvConfig . parsed , process . env ) ;
14
+ }
15
+ } catch ( e ) {
16
+ console . log ( 'No .env file existing or accessible:' , e ) ;
17
+ }
10
18
}
11
19
12
20
module . exports = env ;
Original file line number Diff line number Diff line change 1
- const dotenvConfig = require ( 'dotenv' ) . config ( ) ;
2
1
const pick = require ( 'lodash/pick' ) ;
3
- if ( dotenvConfig . error ) {
4
- throw dotenvConfig . error ;
5
- }
6
- console . log ( 'Parsed .env config:' , dotenvConfig . parsed ) ;
2
+ const dotenvConfig = require ( '../lib/env' ) ;
3
+ console . log ( 'Parsed .env config:' , dotenvConfig ) ;
7
4
console . log ( 'Node version:' , process . version ) ;
8
5
9
6
const apm = require ( '../lib/apm/ServerSide' ) ;
@@ -70,7 +67,7 @@ app.prepare().then(() => {
70
67
71
68
// Defines a filtered set of environment variables to the client.
72
69
server . get ( '/clientEnv.js' , ( req , res ) => {
73
- const envAndDotEnv = { ...dotenvConfig . parsed , ...process . env } ;
70
+ const envAndDotEnv = { ...dotenvConfig , ...process . env } ;
74
71
const filteredEnvObject = JSON . stringify (
75
72
pick (
76
73
envAndDotEnv ,
You can’t perform that action at this time.
0 commit comments