Skip to content

Commit

Permalink
👷 build: remove unnecessary SSL judgments (lobehub#4219)
Browse files Browse the repository at this point in the history
* ♻️ refactor: remove unnecessary SSL judgments

* 🔨 chore: handle `ERR_TLS_CERT_ALTNAME_INVALID` error
  • Loading branch information
hezhijie0327 authored Sep 30, 2024
1 parent 3f4fe82 commit 8e87a4a
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions scripts/serverLauncher/startServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,20 @@ const isValidTLS = (url = '') => {
const options = { host, port, servername: host };
return new Promise((resolve, reject) => {
const socket = tls.connect(options, () => {
if (socket.authorized) {
console.log(`✅ TLS Check: Valid certificate for ${host}:${port}.`);
console.log('-------------------------------------');
resolve();
}
console.log(`✅ TLS Check: Valid certificate for ${host}:${port}.`);
console.log('-------------------------------------');

socket.end();

resolve();
});

socket.on('error', (err) => {
const errMsg = `❌ TLS Check: Error for ${host}:${port}. Details:`;
switch (err.code) {
case 'CERT_HAS_EXPIRED':
case 'DEPTH_ZERO_SELF_SIGNED_CERT':
case 'ERR_TLS_CERT_ALTNAME_INVALID':
console.error(`${errMsg} Certificate is not valid. Consider setting NODE_TLS_REJECT_UNAUTHORIZED="0" or mapping /etc/ssl/certs/ca-certificates.crt.`);
break;
case 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY':
Expand Down

0 comments on commit 8e87a4a

Please sign in to comment.