1
- /**
2
- * Module dependencies.
3
- */
4
-
5
1
import * as program from "commander" ;
6
2
import * as debugModule from "debug" ;
7
3
import * as http from "http" ;
@@ -15,24 +11,11 @@ main().catch(console.error);
15
11
16
12
async function main ( ) {
17
13
const app = await createApp ( ) ;
18
-
19
- /**
20
- * Get port from environment and store in Express.
21
- */
22
-
23
14
const port = normalizePort ( program . port ) ;
24
15
app . set ( "port" , port ) ;
25
16
26
- /**
27
- * Create HTTP server.
28
- */
29
-
30
17
const server = http . createServer ( app ) ;
31
18
32
- /**
33
- * Listen on provided port, on all network interfaces.
34
- */
35
-
36
19
server . listen ( port ) ;
37
20
server . on ( "error" , onError ( port ) ) ;
38
21
server . on ( "listening" , onListening ( server ) ) ;
@@ -58,30 +41,20 @@ async function main() {
58
41
} ) ;
59
42
}
60
43
61
- /**
62
- * Normalize a port into a number, string, or false.
63
- */
64
-
65
44
function normalizePort ( val : string ) {
66
45
const parsedPort = parseInt ( val , 10 ) ;
67
46
68
47
if ( isNaN ( parsedPort ) ) {
69
- // named pipe
70
48
return val ;
71
49
}
72
50
73
51
if ( parsedPort >= 0 ) {
74
- // port number
75
52
return parsedPort ;
76
53
}
77
54
78
55
return false ;
79
56
}
80
57
81
- /**
82
- * Event listener for HTTP server "error" event.
83
- */
84
-
85
58
function onError ( port : any ) : ( error : any ) => void {
86
59
return ( error : any ) => {
87
60
if ( error . syscall !== "listen" ) {
@@ -90,7 +63,6 @@ function onError(port: any): (error: any) => void {
90
63
91
64
const bind = typeof port === "string" ? "Pipe " + port : "Port " + port ;
92
65
93
- // handle specific listen errors with friendly messages
94
66
switch ( error . code ) {
95
67
case "EACCES" :
96
68
console . error ( bind + " requires elevated privileges" ) ;
@@ -106,10 +78,6 @@ function onError(port: any): (error: any) => void {
106
78
} ;
107
79
}
108
80
109
- /**
110
- * Event listener for HTTP server "listening" event.
111
- */
112
-
113
81
function onListening ( server : any ) : ( ) => void {
114
82
return ( ) => {
115
83
const addr = server . address ( ) ;
0 commit comments