Skip to content

Commit 3c42417

Browse files
committed
Update main.ts
1 parent 5d627a0 commit 3c42417

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

src/main.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,19 @@ import { Logger, ValidationPipe } from '@nestjs/common';
55
import * as express from 'express';
66
import { join } from 'path';
77
import * as bodyParser from 'body-parser';
8-
import { readFileSync } from 'fs';
8+
import { readFileSync, existsSync } from 'fs';
99
import { HttpsOptions } from '@nestjs/common/interfaces/external/https-options.interface';
1010

1111
function getHttpsOptions(): HttpsOptions | null {
12-
let cert: Buffer, key: Buffer;
13-
try {
14-
key = readFileSync('./secrets/ssl.key');
15-
} catch (err) {
16-
Logger.error('./secrets/ssl.key not found', err.stack);
17-
}
18-
try {
19-
cert = readFileSync('./secrets/ssl.cert');
20-
} catch (err) {
21-
Logger.error('./secrets/ssl.cert not found', err.stack);
12+
const keyPath = './secrets/ssl.key';
13+
const certPath = './secrets/cert.key';
14+
if (!existsSync(keyPath) || !existsSync(certPath)) {
15+
Logger.log('HTTPS config not found. Fall back to HTTP');
16+
return null;
2217
}
2318
return {
24-
key,
25-
cert,
19+
key: readFileSync(keyPath),
20+
cert: readFileSync(certPath),
2621
};
2722
}
2823

0 commit comments

Comments
 (0)