fix(server): prevent crash when SSL certificate is invalid

This commit is contained in:
Link33d 2025-05-13 00:13:33 -03:00
parent 427c994993
commit 4f467f943e
3 changed files with 25 additions and 9 deletions

View File

@ -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'

View File

@ -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);

View File

@ -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() {