@@ -18,7 +18,10 @@ program.version(pkg.version);
18
18
program
19
19
. option ( "-c --config <webpack-config>" , "additional webpack configuration" )
20
20
. option ( "-p --port <port>" , "port to serve from (default: 9000)" )
21
- . option ( "-t --timeout <timeout>" , "function invocation timeout in seconds (default: 10)" )
21
+ . option (
22
+ "-t --timeout <timeout>" ,
23
+ "function invocation timeout in seconds (default: 10)"
24
+ )
22
25
. option ( "-s --static" , "serve pre-built lambda files" ) ;
23
26
24
27
program
@@ -28,14 +31,21 @@ program
28
31
console . log ( "netlify-lambda: Starting server" ) ;
29
32
var static = Boolean ( program . static ) ;
30
33
if ( static ) return ; // early terminate, don't build
34
+ var server ;
31
35
build . watch ( cmd , program . config , function ( err , stats ) {
32
36
if ( err ) {
33
37
console . error ( err ) ;
34
38
return ;
35
39
}
36
-
40
+
37
41
console . log ( stats . toString ( { color : true } ) ) ;
38
- var server = serve . listen ( program . port || 9000 , static , Number ( program . timeout ) || 10 ) ;
42
+ if ( ! server ) {
43
+ server = serve . listen (
44
+ program . port || 9000 ,
45
+ static ,
46
+ Number ( program . timeout ) || 10
47
+ ) ;
48
+ }
39
49
stats . compilation . chunks . forEach ( function ( chunk ) {
40
50
server . clearCache ( chunk . name ) ;
41
51
} ) ;
@@ -60,11 +70,13 @@ program
60
70
61
71
// error on unknown commands
62
72
// ref: https://github.com/tj/commander.js#custom-event-listeners
63
- program
64
- . on ( 'command:*' , function ( ) {
65
- console . error ( 'Invalid command: %s\nSee --help for a list of available commands.' , program . args . join ( ' ' ) ) ;
66
- process . exit ( 1 ) ;
67
- } ) ;
73
+ program . on ( "command:*" , function ( ) {
74
+ console . error (
75
+ "Invalid command: %s\nSee --help for a list of available commands." ,
76
+ program . args . join ( " " )
77
+ ) ;
78
+ process . exit ( 1 ) ;
79
+ } ) ;
68
80
69
81
program . parse ( process . argv ) ;
70
82
0 commit comments