Skip to content

Commit 9eea904

Browse files
committed
Reduce Promise bodies
1 parent 4294d76 commit 9eea904

File tree

1 file changed

+45
-50
lines changed

1 file changed

+45
-50
lines changed

index.js

Lines changed: 45 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -293,20 +293,21 @@ async function createHttp(httpConfig, log) {
293293
return await createMultiple(createHttp, httpConfig, log);
294294
}
295295

296-
return await new Promise((resolve, reject) => {
297-
var server = require('http').createServer(httpConfig.handler),
298-
timeout = httpConfig.timeout,
299-
port = httpConfig.port,
300-
args;
296+
const
297+
server = require('http').createServer(httpConfig.handler),
298+
timeout = httpConfig.timeout,
299+
port = httpConfig.port;
301300

302-
if (typeof timeout === 'number') server.setTimeout(timeout);
301+
if (typeof timeout === 'number') server.setTimeout(timeout);
303302

304-
args = [server, port];
305-
if (httpConfig.host) {
306-
args.push(httpConfig.host);
307-
}
303+
const args = [server, port];
304+
if (httpConfig.host) {
305+
args.push(httpConfig.host);
306+
}
308307

309-
log('http | try listen ' + port);
308+
log('http | try listen ' + port);
309+
310+
return new Promise((resolve, reject) => {
310311
args.push(function listener(err) {
311312
err ? reject(err) : resolve(server);
312313
});
@@ -328,54 +329,48 @@ async function createHttps(ssl, log, h2) {
328329
return await createMultiple(createHttps, ssl, log, h2);
329330
}
330331

331-
let
332-
port = ssl.port,
333-
timeout = ssl.timeout,
334-
server,
335-
args;
336-
337332
const [key, cert, ca] = await Promise.all([
338333
normalizePEMContent(ssl.root, ssl.key),
339334
normalizeCertContent(ssl.root, ssl.cert, ssl.key),
340335
normalizeCA(ssl.root, ssl.ca)
341336
]);
342337

343-
return await new Promise(async (resolve, reject) => {
344-
const finalHttpsOptions = assign({}, ssl, {
345-
key,
346-
cert,
347-
ca,
348-
//
349-
// Properly expose ciphers for an A+ SSL rating:
350-
// https://certsimple.com/blog/a-plus-node-js-ssl
351-
//
352-
ciphers: normalizeCiphers(ssl.ciphers),
353-
honorCipherOrder: !!ssl.honorCipherOrder,
354-
//
355-
// Protect against the POODLE attack by disabling SSLv3
356-
// @see http://googleonlinesecurity.blogspot.nl/2014/10/this-poodle-bites-exploiting-ssl-30.html
357-
//
358-
secureProtocol: 'SSLv23_method',
359-
secureOptions: secureOptions
360-
});
361-
362-
if (ssl.sni && !finalHttpsOptions.SNICallback) {
363-
finalHttpsOptions.SNICallback = await getSNIHandler(ssl);
364-
}
338+
const finalHttpsOptions = assign({}, ssl, {
339+
key,
340+
cert,
341+
ca,
342+
//
343+
// Properly expose ciphers for an A+ SSL rating:
344+
// https://certsimple.com/blog/a-plus-node-js-ssl
345+
//
346+
ciphers: normalizeCiphers(ssl.ciphers),
347+
honorCipherOrder: !!ssl.honorCipherOrder,
348+
//
349+
// Protect against the POODLE attack by disabling SSLv3
350+
// @see http://googleonlinesecurity.blogspot.nl/2014/10/this-poodle-bites-exploiting-ssl-30.html
351+
//
352+
secureProtocol: 'SSLv23_method',
353+
secureOptions: secureOptions
354+
});
365355

366-
log('https | listening on %d', port);
367-
if(h2) {
368-
server = require('http2').createSecureServer(finalHttpsOptions, ssl.handler)
369-
} else {
370-
server = require('https').createServer(finalHttpsOptions, ssl.handler);
371-
}
356+
if (ssl.sni && !finalHttpsOptions.SNICallback) {
357+
finalHttpsOptions.SNICallback = await getSNIHandler(ssl);
358+
}
372359

373-
if (typeof timeout === 'number') server.setTimeout(timeout);
374-
args = [server, port];
375-
if (ssl.host) {
376-
args.push(ssl.host);
377-
}
360+
const port = ssl.port;
361+
log('https | listening on %d', port);
362+
const server = h2
363+
? require('http2').createSecureServer(finalHttpsOptions, ssl.handler)
364+
: require('https').createServer(finalHttpsOptions, ssl.handler);
365+
366+
const timeout = ssl.timeout;
367+
if (typeof timeout === 'number') server.setTimeout(timeout);
368+
const args = [server, port];
369+
if (ssl.host) {
370+
args.push(ssl.host);
371+
}
378372

373+
return new Promise((resolve, reject) => {
379374
args.push(function listener(err) {
380375
err ? reject(err) : resolve(server);
381376
});

0 commit comments

Comments
 (0)