11using System . Net ;
2+ using System . Net . Sockets ;
23using Microsoft . AspNetCore . DataProtection ;
34using Microsoft . AspNetCore . Identity ;
45using MyApp . Data ;
6970 options . MapEndpoints ( ) ;
7071} ) ;
7172
72- // Proxy development HMR WebSocket and fallback routes to the Next server
7373if ( app . Environment . IsDevelopment ( ) )
7474{
75- // Start the Angular dev server if it's not running
76- bool IsPortAvailable ( int port ) => System . Net . NetworkInformation . IPGlobalProperties . GetIPGlobalProperties ( )
77- . GetActiveTcpListeners ( ) . All ( x => x . Port != port ) ;
78- if ( IsPortAvailable ( 4200 ) && nodeProxy . TryStartNode ( "../MyApp.Client" , out var process ) )
79- {
80- app . Lifetime . ApplicationStopping . Register ( ( ) => {
81- if ( ! process . HasExited )
82- {
83- nodeProxy . Log . LogDebug ( "Terminating process: " + process . Id ) ;
84- process . Kill ( entireProcessTree : true ) ;
85- }
86- } ) ;
87- }
88-
75+ app . RunNodeProcess ( nodeProxy , "../MyApp.Client" ) ; // Start Node if not running
8976 app . UseWebSockets ( ) ;
90- app . MapViteHmr ( nodeProxy ) ;
91- app . MapFallbackToNode ( nodeProxy ) ;
92-
93- // Wait for Angular Dev Server to start...
94- ExecUtils . RetryOnException ( ( ) =>
95- nodeProxy . Client . GetStringAsync ( "/" ) . Wait ( ) , timeOut : TimeSpan . FromSeconds ( 30 ) ) ;
77+ app . MapViteHmr ( nodeProxy ) ; // Proxy HMR WebSocket requests
78+ app . MapFallbackToNode ( nodeProxy ) ; // Fallback to Node dev server in development
9679}
9780else
98- {
99- // Map fallback to index.html in production (MyApp.Client/dist > wwwroot)
100- app . MapFallbackToFile ( "index.html" ) ;
81+ {
82+ app . MapFallbackToFile ( "index.html" ) ; // Fallback to index.html in production (MyApp.Client/dist > wwwroot)
10183}
10284
103- app . Run ( ) ;
85+ app . Run ( ) ;
0 commit comments