Skip to content
10 changes: 10 additions & 0 deletions src/config/ducky-api-config.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,14 @@ export class DuckyApiConfig {
@IsNumber()
@Min(0)
DELAY: number

@IsOptional()
@IsNotEmpty()
@IsString()
TLS_KEY_PATH: string

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
TLS_KEY_PATH: string
TLS_KEY_PATH?: string


@IsOptional()
@IsNotEmpty()
@IsString()
TLS_CERT_PATH: string

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
TLS_CERT_PATH: string
TLS_CERT_PATH?: string

}
12 changes: 11 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,18 @@ const writeFile = promisify(fs.writeFile)
declare const module: any

async function bootstrap(): Promise<void> {
const app = await NestFactory.create(AppModule)
const config: ConfigService = app.get('ConfigService')
let nestConfig = {}

if (config.TLS_KEY_PATH && config.TLS_CERT_PATH) {
const fs = require('fs');
nestConfig.httpsOptions = {
key: fs.readFileSync(config.TLS_KEY_PATH),
cert: fs.readFileSync(config.TLS_CERT_PATH)
};
}

const app = await NestFactory.create(AppModule, nestConfig);

if (config.SERVE_DUCKYPANEL) {
// Write baseurl to file for DuckyPanel to find
Expand Down