Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

create-servers

Package Overview
Dependencies
Maintainers
6
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create-servers - npm Package Compare versions

Comparing version 3.2.0 to 3.2.1

196

index.js

@@ -10,3 +10,4 @@ 'use strict';

var fs = require('fs'),
const
fs = require('fs').promises,
tls = require('tls'),

@@ -19,5 +20,5 @@ path = require('path'),

var pemFormat = /-----BEGIN/;
const pemFormat = /-----BEGIN/;
var CIPHERS = [
const CIPHERS = [
'ECDHE-RSA-AES256-SHA384',

@@ -41,3 +42,3 @@ 'DHE-RSA-AES256-SHA384',

var secureOptions = constants.SSL_OP_NO_SSLv3;
const secureOptions = constants.SSL_OP_NO_SSLv3;

@@ -55,18 +56,15 @@ /**

const [
[httpErr, http],
[httpsErr, https],
[http2Err, http2]] = await Promise.all([
const [httpResult, httpsResult, http2Result] = await Promise.allSettled([
createHttp(options.http, options.log),
createHttps(options.https, options.log),
createHttps(options.http2, options.log, true)
]);
])
const servers = {};
if (http) servers.http = http;
if (https) servers.https = https;
if (http2) servers.http2 = http2;
if (httpResult.value) servers.http = httpResult.value;
if (httpsResult.value) servers.https = httpsResult.value;
if (http2Result.value) servers.http2 = http2Result.value;
if (httpErr || httpsErr || http2Err) {
let errorSource = http2Err || httpsErr || httpErr;
const errorSource = httpResult.reason || httpsResult.reason || http2Result.reason;
if (errorSource) {
if (Array.isArray(errorSource)) {

@@ -78,5 +76,5 @@ errorSource = errorSource[0];

message: errorSource && errorSource.message,
http2: http2Err,
https: httpsErr,
http: httpErr
http2: http2Result.reason,
https: httpsResult.reason,
http: httpResult.reason
}),

@@ -180,13 +178,13 @@ servers

return Array.isArray(data)
? data.map(function(item) {
? Promise.all(data.map(function(item) {
return normalizeCertChain(root, item);
})
}))
: normalizePEMContent(root, data);
}
function normalizeCertChain(root, data) {
async function normalizeCertChain(root, data) {
// A chain can be an array, which we concatenate together into one PEM,
// an already-concatenated chain, or a single PEM
const content = normalizePEMContent(root, data);
const content = await normalizePEMContent(root, data);
return Array.isArray(content) ? content.join('\n') : content;

@@ -199,3 +197,3 @@ }

}
return ca && ca.map(normalizePEMContent.bind(null, root));
return ca && Promise.all(ca.map(normalizePEMContent.bind(null, root)));
}

@@ -211,5 +209,5 @@

if (Array.isArray(file))
return file.map(function map(item) {
return Promise.all(file.map(function map(item) {
return normalizePEMContent(root, item);
});
}));

@@ -223,3 +221,3 @@ //

return fs.readFileSync(path.resolve(root, file));
return fs.readFile(path.resolve(root, file));
}

@@ -238,7 +236,7 @@

function getSNIHandler(sslOpts) {
var sniHosts = Object.keys(sslOpts.sni);
async function getSNIHandler(sslOpts) {
const sniHosts = Object.keys(sslOpts.sni);
// Pre-compile regexps for the hostname
var hostRegexps = sniHosts.map(function(host) {
const hostRegexps = sniHosts.map(function(host) {
return host === '*' ? /.*/ : new RegExp(

@@ -255,3 +253,3 @@ '^' +

// Prepare secure contexts ahead-of-time
var hostSecureContexts = sniHosts.map(function(host) {
const hostSecureContexts = await Promise.all(sniHosts.map(async function(host) {
var hostOpts = sslOpts.sni[host];

@@ -261,7 +259,13 @@

const [key, cert, ca] = await Promise.all([
normalizePEMContent(root, hostOpts.key),
normalizeCertContent(root, hostOpts.cert),
normalizeCA(root, hostOpts.ca || sslOpts.ca)
])
return tls.createSecureContext(
assign({}, sslOpts, hostOpts, {
key: normalizePEMContent(root, hostOpts.key),
cert: normalizeCertContent(root, hostOpts.cert),
ca: normalizeCA(root, hostOpts.ca || sslOpts.ca),
key,
cert,
ca,
ciphers: normalizeCiphers(hostOpts.ciphers || sslOpts.ciphers),

@@ -275,3 +279,3 @@ honorCipherOrder: !!(

);
});
}));

@@ -298,3 +302,3 @@ return function(hostname, cb) {

log('http | no options.http; no server');
return [null, null];
return null;
}

@@ -306,18 +310,19 @@

return await new Promise(resolve => {
var server = require('http').createServer(httpConfig.handler),
timeout = httpConfig.timeout,
port = httpConfig.port,
args;
const
server = require('http').createServer(httpConfig.handler),
timeout = httpConfig.timeout,
port = httpConfig.port;
if (typeof timeout === 'number') server.setTimeout(timeout);
if (typeof timeout === 'number') server.setTimeout(timeout);
args = [server, port];
if (httpConfig.host) {
args.push(httpConfig.host);
}
const args = [server, port];
if (httpConfig.host) {
args.push(httpConfig.host);
}
log('http | try listen ' + port);
log('http | try listen ' + port);
return new Promise((resolve, reject) => {
args.push(function listener(err) {
resolve([err, server]);
err ? reject(err) : resolve(server);
});

@@ -335,3 +340,3 @@ connected.apply(null, args);

log('https | no options.https; no server');
return [null, null];
return null;
}

@@ -343,48 +348,46 @@

return await new Promise(resolve => {
var port = ssl.port,
timeout = ssl.timeout,
server,
args;
const [key, cert, ca] = await Promise.all([
normalizePEMContent(ssl.root, ssl.key),
normalizeCertContent(ssl.root, ssl.cert, ssl.key),
normalizeCA(ssl.root, ssl.ca)
]);
var finalHttpsOptions = assign({}, ssl, {
//
// Load default SSL key, cert and ca(s).
//
key: normalizePEMContent(ssl.root, ssl.key),
cert: normalizeCertContent(ssl.root, ssl.cert, ssl.key),
ca: normalizeCA(ssl.root, ssl.ca),
//
// Properly expose ciphers for an A+ SSL rating:
// https://certsimple.com/blog/a-plus-node-js-ssl
//
ciphers: normalizeCiphers(ssl.ciphers),
honorCipherOrder: !!ssl.honorCipherOrder,
//
// Protect against the POODLE attack by disabling SSLv3
// @see http://googleonlinesecurity.blogspot.nl/2014/10/this-poodle-bites-exploiting-ssl-30.html
//
secureProtocol: 'SSLv23_method',
secureOptions: secureOptions
});
const finalHttpsOptions = assign({}, ssl, {
key,
cert,
ca,
//
// Properly expose ciphers for an A+ SSL rating:
// https://certsimple.com/blog/a-plus-node-js-ssl
//
ciphers: normalizeCiphers(ssl.ciphers),
honorCipherOrder: !!ssl.honorCipherOrder,
//
// Protect against the POODLE attack by disabling SSLv3
// @see http://googleonlinesecurity.blogspot.nl/2014/10/this-poodle-bites-exploiting-ssl-30.html
//
secureProtocol: 'SSLv23_method',
secureOptions: secureOptions
});
if (ssl.sni && !finalHttpsOptions.SNICallback) {
finalHttpsOptions.SNICallback = getSNIHandler(ssl);
}
if (ssl.sni && !finalHttpsOptions.SNICallback) {
finalHttpsOptions.SNICallback = await getSNIHandler(ssl);
}
log('https | listening on %d', port);
if(h2) {
server = require('http2').createSecureServer(finalHttpsOptions, ssl.handler)
} else {
server = require('https').createServer(finalHttpsOptions, ssl.handler);
}
const port = ssl.port;
log('https | listening on %d', port);
const server = h2
? require('http2').createSecureServer(finalHttpsOptions, ssl.handler)
: require('https').createServer(finalHttpsOptions, ssl.handler);
if (typeof timeout === 'number') server.setTimeout(timeout);
args = [server, port];
if (ssl.host) {
args.push(ssl.host);
}
const timeout = ssl.timeout;
if (typeof timeout === 'number') server.setTimeout(timeout);
const args = [server, port];
if (ssl.host) {
args.push(ssl.host);
}
return new Promise((resolve, reject) => {
args.push(function listener(err) {
resolve([err, server]);
err ? reject(err) : resolve(server);
});

@@ -396,12 +399,17 @@ connected.apply(null, args);

async function createMultiple(createFn, configArray, log) {
const errorsOrServers = await Promise.all(
const errorsOrServers = await Promise.allSettled(
configArray.map(cfg => createFn(cfg, log))
);
const errors = [],
servers = [];
for (const [error, server] of errorsOrServers) {
error && errors.push(error);
server && servers.push(server);
const errors = [], servers = [];
for (const result of errorsOrServers) {
result.reason && errors.push(result.reason);
result.value && servers.push(result.value);
}
return [errors.length ? errors : null, servers];
if (errors.length) {
throw errors;
} else {
return servers;
}
}
{
"name": "create-servers",
"version": "3.2.0",
"version": "3.2.1",
"description": "Create an http AND/OR an https server and call the same request handler.",
"main": "index.js",
"files": [
"./index.js"
],
"scripts": {

@@ -7,0 +10,0 @@ "test": "node test/create-servers-test.js"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc