mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-20 10:16:43 -06:00
fix(server): prevent crash when SSL certificate is invalid
This commit is contained in:
parent
427c994993
commit
4f467f943e
@ -3,6 +3,10 @@ SERVER_PORT=8080
|
||||
# Server URL - Set your application url
|
||||
SERVER_URL=http://localhost:8080
|
||||
|
||||
# Paths to your SSL certificate files (used for HTTPS)
|
||||
SSL_CONF_PRIVKEY=/path/to/cert.key
|
||||
SSL_CONF_FULLCHAIN=/path/to/cert.crt
|
||||
|
||||
SENTRY_DSN=
|
||||
|
||||
# Cors - * for all or set separate by commas - ex.: 'yourdomain1.com, yourdomain2.com'
|
||||
|
10
src/main.ts
10
src/main.ts
@ -128,7 +128,15 @@ async function bootstrap() {
|
||||
const httpServer = configService.get<HttpServer>('SERVER');
|
||||
|
||||
ServerUP.app = app;
|
||||
const server = ServerUP[httpServer.TYPE];
|
||||
let server = ServerUP[httpServer.TYPE];
|
||||
|
||||
if (server === null) {
|
||||
logger.warn("SSL cert load failed — falling back to HTTP.")
|
||||
logger.info("Ensure 'SSL_CONF_PRIVKEY' and 'SSL_CONF_FULLCHAIN' env vars point to valid certificate files.");
|
||||
|
||||
httpServer.TYPE = "http"
|
||||
server = ServerUP[httpServer.TYPE]
|
||||
}
|
||||
|
||||
eventManager.init(server);
|
||||
|
||||
|
@ -12,6 +12,7 @@ export class ServerUP {
|
||||
}
|
||||
|
||||
static get https() {
|
||||
try {
|
||||
const { FULLCHAIN, PRIVKEY } = configService.get<SslConf>('SSL_CONF');
|
||||
return https.createServer(
|
||||
{
|
||||
@ -20,6 +21,9 @@ export class ServerUP {
|
||||
},
|
||||
ServerUP.#app,
|
||||
);
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
static get http() {
|
||||
|
Loading…
Reference in New Issue
Block a user