File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
packages/angular_devkit/build_angular/src/builders/dev-server Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -186,6 +186,16 @@ case.
186186 ) ;
187187 }
188188
189+ // Overwrite port, if process.env.PORT is available.
190+ if ( process . env . PORT ) {
191+ const envPort = Number ( process . env . PORT ) ;
192+
193+ if ( ! isNaN ( envPort ) ) {
194+ normalizedOptions . port = envPort ;
195+ context . logger . info ( 'process.env.PORT detected. Port set to ' + envPort ) ;
196+ }
197+ }
198+
189199 normalizedOptions . port = await checkPort ( normalizedOptions . port , normalizedOptions . host ) ;
190200
191201 return {
Original file line number Diff line number Diff line change @@ -107,6 +107,25 @@ describeServeBuilder(
107107 ) ;
108108 }
109109 } ) ;
110+
111+ it ( 'should be overwritten by process.env.PORT if it exists' , async ( ) => {
112+ harness . useTarget ( 'serve' , {
113+ ...BASE_OPTIONS ,
114+ port : 8000 ,
115+ } ) ;
116+
117+ process . env . PORT = '4201' ;
118+
119+ const { result, response } = await executeOnceAndFetch ( harness , '/' ) ;
120+
121+ expect ( result ?. success ) . toBeTrue ( ) ;
122+ expect ( getResultPort ( result ) ) . toBe ( '4201' ) ;
123+ expect ( await response ?. text ( ) ) . toContain ( '<title>' ) ;
124+
125+ expect ( 1 ) . toEqual ( 2 ) ;
126+
127+ delete process . env . PORT ;
128+ } ) ;
110129 } ) ;
111130 } ,
112131) ;
You can’t perform that action at this time.
0 commit comments