Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.then(() => {
if (dev || process.env.LOCAL_ENV) {
// Always support localhost as it is what people expect
server.listen(port, (err) => {
if (err) throw err;
// eslint-disable-next-line
console.log(`> Ready on http://localhost:${port}`);
});
// This will do a one time certificate password request the first time you start.
// It will also attempt to add your certificateFor domain to hosts. If you
// get access errors, add "www.myweb.com 127.0.0.1" to hosts file manually.
// devcert.certificateFor("www.myweb.com", {installCertutil: true}).then((ssl) => {
devcert.certificateFor("www.myweb.com", {installCertutil: true}).then((ssl) => {
https.createServer(ssl, server).listen(devSslPort, (err) => {
if (err) throw err;
// eslint-disable-next-line
console.log(`> Ready on https://www.myweb.com:${devSslPort}`);
});
});
} else {
server.listen(port, (err) => {
if (err) throw err;
// eslint-disable-next-line
console.log(`> Ready on http://localhost:${port}`);
});
}
});
}
export async function getCertificates({key, cert, production, host, https}: IGetCertificateOptions): Promise<{key: Buffer | undefined; cert: Buffer | undefined}> {
// If a key and certificate was already given, use those two
if (key != null && cert != null) return {key, cert};
// Otherwise, if not in production, use devcert to generate a new certificate
if (!production && https) {
return await certificateFor(host);
}
// Return nothing
return {key: undefined, cert: undefined};
}
debug('appears to be a sudo session already');
}
} else {
debug(
'non-interactive! cleared UI timeout for getCert("%s")',
hostname
);
clearTimeout(timeout);
return reject(
new Error(
'Creating a local development domain requires an interactive terminal for the user to answer prompts. Run the development server (e.g. `yarn run watch:venia`) by itself in the terminal to continue.'
)
);
}
}
const certBuffers = await devcert.certificateFor(hostname);
debug('certBuffers arrived with %s', Object.keys(certBuffers));
debug('success! cleared UI timeout for getCert("%s")', hostname);
clearTimeout(timeout);
resolve({
key: certBuffers.key.toString('utf8'),
cert: certBuffers.cert.toString('utf8')
});
} catch (e) {
clearTimeout(timeout);
debug(
'failure! cleared UI timeout for getCert("%s"): %o',
hostname,
e
);
reject(e);
}