@@ -31,8 +31,7 @@ function shouldMigrateDatabase(store) {
3131}
3232
3333function shouldOptimize ( store ) {
34- return store . get ( 'optimized_version' ) !== app . getVersion ( )
35- && process . env . NODE_ENV !== 'development' ;
34+ return store . get ( 'optimized_version' ) !== app . getVersion ( ) ;
3635}
3736
3837async function getPhpPort ( ) {
@@ -253,7 +252,7 @@ function getDefaultEnvironmentVariables(secret, apiPort): EnvironmentVariables {
253252 } ;
254253
255254 // Only add cache paths if in production mode
256- if ( runningSecureBuild ( ) ) {
255+ if ( runningSecureBuild ( ) ) {
257256 variables . APP_SERVICES_CACHE = join ( bootstrapCache , 'services.php' ) ;
258257 variables . APP_PACKAGES_CACHE = join ( bootstrapCache , 'packages.php' ) ;
259258 variables . APP_CONFIG_CACHE = join ( bootstrapCache , 'config.php' ) ;
@@ -296,6 +295,7 @@ function serveApp(secret, apiPort, phpIniSettings): Promise<ProcessResult> {
296295 // Make sure the storage path is linked - as people can move the app around, we
297296 // need to run this every time the app starts
298297 if ( ! runningSecureBuild ( ) ) {
298+ console . log ( 'Linking storage path...' ) ;
299299 callPhpSync ( [ 'artisan' , 'storage:link' , '--force' ] , phpOptions , phpIniSettings )
300300 }
301301
@@ -333,33 +333,38 @@ function serveApp(secret, apiPort, phpIniSettings): Promise<ProcessResult> {
333333 const phpPort = await getPhpPort ( ) ;
334334
335335
336- let serverPath = join ( appPath , 'build' , '__nativephp_app_bundle' ) ;
336+ let serverPath : string ;
337+ let cwd : string ;
337338
338- if ( ! runningSecureBuild ( ) ) {
339+ if ( runningSecureBuild ( ) ) {
340+ serverPath = join ( appPath , 'build' , '__nativephp_app_bundle' ) ;
341+ } else {
339342 console . log ( '* * * Running from source * * *' ) ;
340343 serverPath = join ( appPath , 'vendor' , 'laravel' , 'framework' , 'src' , 'Illuminate' , 'Foundation' , 'resources' , 'server.php' ) ;
344+ cwd = join ( appPath , 'public' ) ;
341345 }
342346
343347 const phpServer = callPhp ( [ '-S' , `127.0.0.1:${ phpPort } ` , serverPath ] , {
344- cwd : join ( appPath , 'public' ) ,
348+ cwd : cwd ,
345349 env
346350 } , phpIniSettings )
347351
348352 const portRegex = / D e v e l o p m e n t S e r v e r \( .* : ( [ 0 - 9 ] + ) \) s t a r t e d / gm
349353
354+ // Show urls called
350355 phpServer . stdout . on ( 'data' , ( data ) => {
351356 // [Tue Jan 14 19:51:00 2025] 127.0.0.1:52779 [POST] URI: /_native/api/events
352357
353358 if ( parseInt ( process . env . SHELL_VERBOSITY ) > 0 ) {
354- console . log ( data . toString ( ) ) ;
359+ console . log ( data . toString ( ) . trim ( ) ) ;
355360 }
356361 } )
357362
358-
363+ // Show PHP errors and indicate which port the server is running on
359364 phpServer . stderr . on ( 'data' , ( data ) => {
360365 const error = data . toString ( ) ;
361366 const match = portRegex . exec ( data . toString ( ) ) ;
362- // console.log('E:', error);
367+
363368 if ( match ) {
364369 const port = parseInt ( match [ 1 ] ) ;
365370 console . log ( "PHP Server started on port: " , port ) ;
@@ -368,23 +373,25 @@ function serveApp(secret, apiPort, phpIniSettings): Promise<ProcessResult> {
368373 process : phpServer ,
369374 } ) ;
370375 } else {
371-
372- // Starting at [NATIVE_EXCEPTION]:
373376 if ( error . includes ( '[NATIVE_EXCEPTION]:' ) ) {
377+ let logFile = join ( storagePath , 'logs' , 'laravel.log' ) ;
378+
374379 console . log ( ) ;
375380 console . error ( 'Error in PHP:' ) ;
376381 console . error ( ' ' + error . split ( '[NATIVE_EXCEPTION]:' ) [ 1 ] . trim ( ) ) ;
377382 console . log ( 'Please check your log file:' ) ;
378- console . log ( ' ' + join ( appPath , 'storage' , 'logs' , 'laravel.log' ) ) ;
383+ console . log ( ' ' + logFile ) ;
379384 console . log ( ) ;
380385 }
381386 }
382387 } ) ;
383388
389+ // Log when any error occurs (not started, not killed, couldn't send message, etc)
384390 phpServer . on ( 'error' , ( error ) => {
385391 reject ( error )
386392 } ) ;
387393
394+ // Log when the PHP server exits
388395 phpServer . on ( 'close' , ( code ) => {
389396 console . log ( `PHP server exited with code ${ code } ` ) ;
390397 } ) ;
0 commit comments