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 - Set your application url
|
||||||
SERVER_URL=http://localhost:8080
|
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=
|
SENTRY_DSN=
|
||||||
|
|
||||||
# Cors - * for all or set separate by commas - ex.: 'yourdomain1.com, yourdomain2.com'
|
# 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');
|
const httpServer = configService.get<HttpServer>('SERVER');
|
||||||
|
|
||||||
ServerUP.app = app;
|
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);
|
eventManager.init(server);
|
||||||
|
|
||||||
|
@ -12,14 +12,18 @@ export class ServerUP {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static get https() {
|
static get https() {
|
||||||
const { FULLCHAIN, PRIVKEY } = configService.get<SslConf>('SSL_CONF');
|
try {
|
||||||
return https.createServer(
|
const { FULLCHAIN, PRIVKEY } = configService.get<SslConf>('SSL_CONF');
|
||||||
{
|
return https.createServer(
|
||||||
cert: readFileSync(FULLCHAIN),
|
{
|
||||||
key: readFileSync(PRIVKEY),
|
cert: readFileSync(FULLCHAIN),
|
||||||
},
|
key: readFileSync(PRIVKEY),
|
||||||
ServerUP.#app,
|
},
|
||||||
);
|
ServerUP.#app,
|
||||||
|
);
|
||||||
|
} catch {
|
||||||
|
return null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static get http() {
|
static get http() {
|
||||||
|
Loading…
Reference in New Issue
Block a user