Skip to content

Commit d0e747d

Browse files
authored
[INTERNAL] Update and add more jsdoc for server, sslUtil and middleware
1 parent 3ff2fb9 commit d0e747d

File tree

7 files changed

+94
-18
lines changed

7 files changed

+94
-18
lines changed

lib/middleware/discovery.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@ const librariesPattern = /([A-Z0-9._%+-/]+)\/[A-Z0-9._]*\.library$/i;
22
const testPagesPattern = /(([A-Z0-9._%+-]+\/)+([A-Z_0-9-\\.]+)\.(html|htm))$/i;
33
const urlPattern = /\/(app_pages|all_libs|all_tests)(?:[?#].*)?$/;
44

5+
/**
6+
* Creates and returns the middleware to discover project files.
7+
*
8+
* List project files with URL (needed exclusively by the OpenUI5 testsuite):
9+
* <ul>
10+
* <li>/discovery/app_pages: get application pages</li>
11+
* <li>/discovery/all_libs: list all libraries</li>
12+
* <li>/discovery/all_tests: list all tests</li>
13+
* </ul>
14+
*
15+
* @module server/middleware/discovery
16+
* @param {Object} resourceCollections Contains the resource reader or collection to access project related files
17+
* @param {AbstractReader} resourceCollections.source Resource reader or collection for the source project
18+
* @param {AbstractReader} resourceCollections.combo Resource collection which contains the workspace and the project dependencies
19+
* @returns {function} Returns a server middleware closure.
20+
*/
521
function createMiddleware({resourceCollections}) {
622
return function discoveryMiddleware(req, res, next) {
723
var parts = urlPattern.exec(req.url);

lib/middleware/nonReadRequests.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
function createMiddleware({resourceCollections}) {
1+
/**
2+
* Creates and returns the middleware to handle non read requests.
3+
*
4+
* Handles non read requests (POST, PUT, DELETE...) and returns an error 404,
5+
* because those operations aren't supported by the server.
6+
*
7+
* @module server/middleware/nonReadRequests
8+
* @returns {function} Returns a server middleware closure.
9+
*/
10+
function createMiddleware() {
211
return function nonReadRequests(req, res, next) {
312
// Handle anything but read operations *before* the serveIndex middleware
413
// as it will reject them with a 405 (Method not allowed) instead of 404 like our old tooling

lib/middleware/serveResources.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ function isFresh(req, res) {
1313
});
1414
}
1515

16+
17+
/**
18+
* Creates and returns the middleware to serve application resources.
19+
*
20+
* @module server/middleware/serveResources
21+
* @param {Object} resourceCollections Contains the resource reader or collection to access project related files
22+
* @param {AbstractReader} resourceCollections.combo Resource collection which contains the workspace and the project dependencies
23+
* @returns {function} Returns a server middleware closure.
24+
*/
1625
function createMiddleware({resourceCollections}) {
1726
return function serveResources(req, res, next) {
1827
resourceCollections.combo.byPath(req.path).then(function(resource) {

lib/middleware/serveThemes.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ function isFresh(req, res) {
1111

1212
const themeRequest = /^(.*\/)library(?:(\.css)|(-RTL\.css)|(-parameters\.json))$/i;
1313

14+
/**
15+
* Creates and returns the middleware to build themes.
16+
*
17+
* The theme is built in realtime. If a less file was modified, the theme build is triggered to rebuild the theme.
18+
*
19+
* @module server/middleware/serveThemes
20+
* @param {Object} resourceCollections Contains the resource reader or collection to access project related files
21+
* @param {AbstractReader} resourceCollections.combo Resource collection which contains the workspace and the project dependencies
22+
* @returns {function} Returns a server middleware closure.
23+
*/
1424
function createMiddleware({resourceCollections}) {
1525
const builder = new themeBuilder.ThemeBuilder({
1626
fs: fsInterface(resourceCollections.combo)

lib/middleware/versionInfo.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
const createVersionInfoProcessor = require("@ui5/builder").processors.versionInfoGenerator;
22

3+
/**
4+
* Creates and returns the middleware to create the version info as json object.
5+
*
6+
* @module server/middleware/versionInfo
7+
* @param {Object} resourceCollections Contains the resource reader or collection to access project related files
8+
* @param {AbstractReader} resourceCollections.dependencies Resource collection which contains the project dependencies
9+
* @returns {function} Returns a server middleware closure.
10+
*/
311
function createMiddleware({resourceCollections, tree: project}) {
412
return function versionInfo(req, res, next) {
513
resourceCollections.dependencies.byGlob("/**/.library")

lib/server.js

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@ const fsInterface = ui5Fs.fsInterface;
1919
* Start a server for the given project (sub-)tree
2020
*
2121
* @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.
3132
*/
3233
function serve(tree, {port, changePortIfInUse = false, h2 = false, key, cert, acceptRemoteConnections = false}) {
3334
return Promise.resolve().then(() => {
@@ -72,7 +73,7 @@ function serve(tree, {port, changePortIfInUse = false, h2 = false, key, cert, ac
7273
}));
7374

7475
if (h2) {
75-
return addSsl({app, h2, key, cert});
76+
return _addSsl({app, h2, key, cert});
7677
}
7778
return app;
7879
}).then((app) => {
@@ -88,6 +89,16 @@ function serve(tree, {port, changePortIfInUse = false, h2 = false, key, cert, ac
8889
});
8990
}
9091

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+
*/
91102
function _listen(app, port, changePortIfInUse, acceptRemoteConnections) {
92103
return new Promise(function(resolve, reject) {
93104
const options = {};
@@ -132,7 +143,16 @@ function _listen(app, port, changePortIfInUse, acceptRemoteConnections) {
132143
});
133144
}
134145

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}) {
136156
// Using spdy as http2 server as the native http2 implementation
137157
// from Node v8.4.0 doesn't seem to work with express
138158
return require("spdy").createServer({cert, key}, app);

lib/sslUtil.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,19 @@ var prompt = require("prompt");
1414

1515
const sslUtil = {
1616
/**
17-
* @param {string} [keyPath=$HOME/.ui5/server/server.key] Path to private key to be used for https.
18-
* Defaults to <pre>$HOME/.ui5/server/server.key</pre>
19-
* @param {string} [certPath=$HOME/.ui5/server/server.crt] Path to certificate to be used for for https.
20-
* Defaults to <pre>$HOME/.ui5/server/server.crt</pre>
21-
* @returns {Promise.<object>} Resolves with an sslObject containing <pre>cert</pre> and <pre>key</pre>
17+
* Creates a new SSL certificate or validates an existing one.
18+
*
19+
* @module server/sslUtil
20+
* @param {string} [keyPath=$HOME/.ui5/server/server.key] Path to private key to be used for https.
21+
* Defaults to <code>$HOME/.ui5/server/server.key</code>
22+
* @param {string} [certPath=$HOME/.ui5/server/server.crt] Path to certificate to be used for for https.
23+
* Defaults to <code>$HOME/.ui5/server/server.crt</codee>
24+
* @returns {Promise<object>} Resolves with an sslObject containing <code>cert</code> and <code>key</code>
2225
*/
2326
getSslCertificate: function(
2427
keyPath = path.join(os.homedir(), ".ui5/server/server.key"),
25-
certPath = path.join(os.homedir(), ".ui5/server/server.crt")) {
28+
certPath = path.join(os.homedir(), ".ui5/server/server.crt")
29+
) {
2630
// checks the certificates if they are present
2731
return Promise.all([
2832
fileExists(keyPath).then((bExists) => {

0 commit comments

Comments
 (0)