File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -79,6 +79,19 @@ function serve (options = { contentBase: '' }) {
7979 server = createServer ( requestListener ) . listen ( options . port , options . host )
8080 }
8181
82+ // Assemble url for error and info messages
83+ const url = ( options . https ? 'https' : 'http' ) + '://' + ( options . host || 'localhost' ) + ':' + options . port
84+
85+ // Handle common server errors
86+ server . on ( 'error' , e => {
87+ if ( e . code === 'EADDRINUSE' ) {
88+ console . error ( url + ' is in use, either stop the other server or use a different port.' )
89+ process . exit ( )
90+ } else {
91+ throw e
92+ }
93+ } )
94+
8295 let first = true
8396
8497 return {
@@ -88,7 +101,6 @@ function serve (options = { contentBase: '' }) {
88101 first = false
89102
90103 // Log which url to visit
91- const url = ( options . https ? 'https' : 'http' ) + '://' + ( options . host || 'localhost' ) + ':' + options . port
92104 if ( options . verbose !== false ) {
93105 options . contentBase . forEach ( base => {
94106 console . log ( green ( url ) + ' -> ' + resolve ( base ) )
You can’t perform that action at this time.
0 commit comments