@@ -3,20 +3,27 @@ import ngrok from 'ngrok';
33import dotenv from 'dotenv-mono' ;
44import chalk from 'chalk' ;
55import { startDockerContainer , stopDockerContainer } from 'database' ;
6- import { app } from './server.js' ;
76
87// If DEV is true then change the port we are running on, to prevent undesired caching
98const BACKEND_PORT = process . env . NODE_ENV === 'dev' ? 8081 : 8080 ;
109
1110dotenv . load ( { path : '.env' } ) ;
1211dotenv . load ( { path : '.env.local' } ) ;
1312
13+ function parseBooleanEnv ( value : string | undefined ) : boolean | undefined {
14+ if ( value == undefined ) return undefined ;
15+ const normalized = value . trim ( ) . toLowerCase ( ) ;
16+ if ( normalized . length === 0 ) return undefined ;
17+ if ( [ '1' , 'true' , 'yes' , 'on' ] . includes ( normalized ) ) return true ;
18+ if ( [ '0' , 'false' , 'no' , 'off' ] . includes ( normalized ) ) return false ;
19+ return undefined ;
20+ }
21+
1422const REMOTE = process . env . LOCATION === 'remote' ;
1523const isDev = process . env . NODE_ENV === 'dev' ;
16- const devUseDocker = [ '1' , 'true' , 'yes' , 'on' ] . includes (
17- String ( process . env . DEV_USE_DOCKER ?? '' ) . toLowerCase ( )
18- ) ;
19- const dbEnabled = ! isDev || devUseDocker ;
24+ const devUseDocker = parseBooleanEnv ( process . env . DEV_USE_DOCKER ) === true ;
25+ const explicitDbEnabled = parseBooleanEnv ( process . env . DB_ENABLED ) ;
26+ const dbEnabled = explicitDbEnabled ?? ( ! isDev || devUseDocker ) ;
2027process . env . DB_ENABLED = dbEnabled ? 'true' : 'false' ;
2128
2229let container : Awaited < ReturnType < typeof startDockerContainer > > | null = null ;
@@ -33,6 +40,8 @@ if (dbEnabled) {
3340 ) ;
3441}
3542
43+ const { app } = await import ( './server.js' ) ;
44+
3645const server = app . listen ( BACKEND_PORT , ( ) => {
3746 console . log ( chalk . green ( 'Server running at http://localhost:' + BACKEND_PORT ) ) ;
3847} ) ;
0 commit comments