@@ -19,15 +19,16 @@ const fsInterface = ui5Fs.fsInterface;
19
19
* Start a server for the given project (sub-)tree
20
20
*
21
21
* @module server/server
22
- * @param {Object } tree A (sub-)tree
23
- * @param {Object } options Options
24
- * @param {string } options.port Port to listen to
25
- * @param {boolean } [options.changePortIfInUse=false] If true, change the port if it is already in use
26
- * @param {string } [options.protocol=http] Protocol to be used (http|https|h2) - defaults to <pre>http</pre>
27
- * @param {string } [options.key] Path to private key to be used for https
28
- * @param {string } [options.cert] Path to certificate to be used for for https
29
-
30
- * @returns {Promise } Promise resolving with an object containing the <pre>port</pre> once the server is listening
22
+ * @param {Object } tree A (sub-)tree
23
+ * @param {Object } options Options
24
+ * @param {number } options.port Port to listen to
25
+ * @param {boolean } [options.changePortIfInUse=false] If true, change the port if it is already in use
26
+ * @param {boolean } [options.h2=false] Whether HTTP/2 should be used - defaults to <code>http</code>
27
+ * @param {string } [options.key] Path to private key to be used for https
28
+ * @param {string } [options.cert] Path to certificate to be used for for https
29
+ * @param {boolean } [options.acceptRemoteConnections=false] If true, listens to remote connections and not only to localhost connections
30
+ * @returns {Promise<Object> } Promise resolving once the server is listening. It resolves with an object containing the <code>port</code>,
31
+ * <code>h2</code>-flag and a <code>close</code> function, which can be used to stop the server.
31
32
*/
32
33
function serve ( tree , { port, changePortIfInUse = false , h2 = false , key, cert, acceptRemoteConnections = false } ) {
33
34
return Promise . resolve ( ) . then ( ( ) => {
@@ -72,7 +73,7 @@ function serve(tree, {port, changePortIfInUse = false, h2 = false, key, cert, ac
72
73
} ) ) ;
73
74
74
75
if ( h2 ) {
75
- return addSsl ( { app, h2, key, cert} ) ;
76
+ return _addSsl ( { app, h2, key, cert} ) ;
76
77
}
77
78
return app ;
78
79
} ) . then ( ( app ) => {
@@ -88,6 +89,16 @@ function serve(tree, {port, changePortIfInUse = false, h2 = false, key, cert, ac
88
89
} ) ;
89
90
}
90
91
92
+ /**
93
+ * Returns a promise resolving by starting the server.
94
+ *
95
+ * @param {Object } app The express applicaton object
96
+ * @param {number } port Desired port to listen to
97
+ * @param {boolean } changePortIfInUse If true and the port is already in use, an unused port is searched
98
+ * @param {boolean } acceptRemoteConnections If true, listens to remote connections and not only to localhost connections
99
+ * @returns {Promise<Object> } Returns an object containing server related information like (selected port, protocol)
100
+ * @private
101
+ */
91
102
function _listen ( app , port , changePortIfInUse , acceptRemoteConnections ) {
92
103
return new Promise ( function ( resolve , reject ) {
93
104
const options = { } ;
@@ -132,7 +143,16 @@ function _listen(app, port, changePortIfInUse, acceptRemoteConnections) {
132
143
} ) ;
133
144
}
134
145
135
- function addSsl ( { app, protocol, key, cert} ) {
146
+ /**
147
+ * Adds SSL support to an express application
148
+ *
149
+ * @param {Object } app The original express application
150
+ * @param {string } key Path to private key to be used for https
151
+ * @param {string } cert Path to certificate to be used for for https
152
+ * @returns {Object } The express application with SSL support
153
+ * @private
154
+ */
155
+ function _addSsl ( { app, key, cert} ) {
136
156
// Using spdy as http2 server as the native http2 implementation
137
157
// from Node v8.4.0 doesn't seem to work with express
138
158
return require ( "spdy" ) . createServer ( { cert, key} , app ) ;
0 commit comments