@@ -30,11 +30,18 @@ import {
30
30
catchError ,
31
31
startWith ,
32
32
mapTo ,
33
+ ignoreElements ,
33
34
} from 'rxjs/operators' ;
34
- import { getAvailablePort , execAsObservable } from './utils' ;
35
+ import { getAvailablePort , spawnAsObservable } from './utils' ;
35
36
import * as browserSync from 'browser-sync' ;
36
37
import { join } from 'path' ;
37
38
39
+ /** Log messages to ignore and not rely to the logger */
40
+ const IGNORED_STDOUT_MESSAGES = [
41
+ 'server listening on' ,
42
+ 'Angular is running in the development mode. Call enableProdMode() to enable the production mode.'
43
+ ] ;
44
+
38
45
export type SSRDevServerBuilderOptions = Schema & json . JsonObject ;
39
46
40
47
export function execute (
@@ -77,7 +84,7 @@ export function execute(
77
84
if ( ! s . success ) {
78
85
return of ( s ) ;
79
86
}
80
- return startNodeServer ( s , nodeServerPort ) . pipe (
87
+ return startNodeServer ( s , nodeServerPort , context . logger ) . pipe (
81
88
mapTo ( s ) ,
82
89
catchError ( err => {
83
90
context . logger . error ( `A server error has occurred.\n${ mapErrorToMessage ( err ) } ` ) ;
@@ -126,16 +133,29 @@ export function execute(
126
133
) ;
127
134
}
128
135
129
- function startNodeServer ( serverOutput : BuilderOutput , port : number ) : Observable < void > {
136
+ function startNodeServer (
137
+ serverOutput : BuilderOutput ,
138
+ port : number ,
139
+ logger : logging . LoggerApi ,
140
+ ) : Observable < void > {
130
141
const outputPath = serverOutput . outputPath as string ;
131
142
const path = join ( outputPath , 'main.js' ) ;
132
143
const env = { ...process . env , PORT : '' + port } ;
133
144
134
- return execAsObservable ( ` node ${ path } ` , { env } )
145
+ return spawnAsObservable ( ' node' , [ `" ${ path } "` ] , { env, shell : true } )
135
146
. pipe (
136
147
// Emit a signal after the process has been started
148
+ tap ( ( { stderr, stdout } ) => {
149
+ if ( stderr ) {
150
+ logger . error ( stderr ) ;
151
+ }
152
+
153
+ if ( stdout && ! IGNORED_STDOUT_MESSAGES . some ( x => stdout . includes ( x ) ) ) {
154
+ logger . info ( stdout ) ;
155
+ }
156
+ } ) ,
157
+ ignoreElements ( ) ,
137
158
startWith ( undefined ) ,
138
- mapTo ( undefined ) ,
139
159
) ;
140
160
}
141
161
0 commit comments