File tree 1 file changed +13
-1
lines changed
1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -79,6 +79,19 @@ function serve (options = { contentBase: '' }) {
79
79
server = createServer ( requestListener ) . listen ( options . port , options . host )
80
80
}
81
81
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
+
82
95
let first = true
83
96
84
97
return {
@@ -88,7 +101,6 @@ function serve (options = { contentBase: '' }) {
88
101
first = false
89
102
90
103
// Log which url to visit
91
- const url = ( options . https ? 'https' : 'http' ) + '://' + ( options . host || 'localhost' ) + ':' + options . port
92
104
if ( options . verbose !== false ) {
93
105
options . contentBase . forEach ( base => {
94
106
console . log ( green ( url ) + ' -> ' + resolve ( base ) )
You can’t perform that action at this time.
0 commit comments