Skip to content

Commit

Permalink
fix(server-dev): Load .env using dotenv.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gervwyk committed May 24, 2022
1 parent ac34fe8 commit 85d7827
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/server-dev/manager/processes/initialBuild.mjs
Expand Up @@ -17,10 +17,10 @@

function initialBuild(context) {
return async () => {
context.readDotEnv();
await context.lowdefyBuild();
await context.installPlugins();
await context.nextBuild();
await context.readDotEnv();
};
}

Expand Down
6 changes: 2 additions & 4 deletions packages/server-dev/manager/processes/readDotEnv.mjs
Expand Up @@ -16,12 +16,10 @@

import path from 'path';
import dotenv from 'dotenv';
import { readFile } from '@lowdefy/node-utils';

function readDotEnv(context) {
return async () => {
const dotEnv = await readFile(path.join(context.directories.config, '.env'));
context.serverEnv = dotenv.parse(dotEnv || '');
return () => {
dotenv.config({ path: path.join(context.directories.config, '.env'), silent: true });
};
}

Expand Down
1 change: 0 additions & 1 deletion packages/server-dev/manager/processes/startNextServer.mjs
Expand Up @@ -27,7 +27,6 @@ function startServerProcess(context) {
processOptions: {
env: {
...process.env,
...context.serverEnv,
PORT: context.options.port,
},
},
Expand Down
3 changes: 2 additions & 1 deletion packages/server-dev/manager/watchers/envWatcher.mjs
Expand Up @@ -21,7 +21,8 @@ import setupWatcher from '../utils/setupWatcher.mjs';
function envWatcher(context) {
const callback = async () => {
console.warn('.env file changed.');
await context.readDotEnv();
context.readDotEnv();
await context.lowdefyBuild();
context.restartServer();
};
return setupWatcher({
Expand Down

0 comments on commit 85d7827

Please sign in to comment.