From d4090b24c799dcd3dd2ed48cabe13b7bbe58dcb1 Mon Sep 17 00:00:00 2001 From: josephine Date: Wed, 24 Jun 2026 08:29:55 +0200 Subject: [PATCH 1/2] feat: aadd ssl config to json configuration --- src/action/actions/start.action.ts | 29 ++++++++++++++++++++++------- src/lib/config/config-defaults.ts | 5 +++++ src/lib/config/config.type.ts | 19 +++++++++++++++++++ 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/src/action/actions/start.action.ts b/src/action/actions/start.action.ts index e6e87c4..2c4c582 100644 --- a/src/action/actions/start.action.ts +++ b/src/action/actions/start.action.ts @@ -42,7 +42,7 @@ export class StartAction extends AbstractAction { const serverDir = getStringInputWithDefault(options, "serverDir", config.server.outDir); const watch = getWatchInput(options); const port = getStringInputWithDefault(options, "port", config.client.port); - const ssl = this.resolveSSL(options); + const ssl = this.resolveSSL(options, config); const tasks = this.buildStartTasks(config, directory, { clientDir, @@ -56,14 +56,29 @@ export class StartAction extends AbstractAction { return { keepAlive: true }; } - private resolveSSL(options: Input): SSLOptions | undefined { - const cert = getStringInput(options, "cert"); - const key = getStringInput(options, "key"); + private resolveSSL(options: Input, config: Config): SSLOptions | undefined { + const cliCert = getStringInput(options, "cert"); + const cliKey = getStringInput(options, "key"); + const isSslRequested = Boolean(cliCert || cliKey || config.ssl?.enable); - if (!cert && !key) return undefined; + if (!isSslRequested) return undefined; - if (!cert) throw new CLIError("No cert entered for SSL. Please enter a cert with --cert."); - if (!key) throw new CLIError("No key entered for SSL. Please enter a key with --key."); + const cert = cliCert || config.ssl?.cert; + const key = cliKey || config.ssl?.key; + + if (!cert) { + throw new CLIError( + "No certificate found for SSL.", + "Please provide a certificate path with --cert or configure 'ssl.cert' in your nanoforge.config.json.", + ); + } + + if (!key) { + throw new CLIError( + "No key found for SSL.", + "Please provide a key path with --key or configure 'ssl.key' in your nanoforge.config.json.", + ); + } return { cert, diff --git a/src/lib/config/config-defaults.ts b/src/lib/config/config-defaults.ts index e753b2a..cb7e1f6 100644 --- a/src/lib/config/config-defaults.ts +++ b/src/lib/config/config-defaults.ts @@ -4,6 +4,11 @@ export const CONFIG_DEFAULTS: Config = { name: "nanoforge-app", language: "ts", initFunctions: true, + ssl: { + enable: false, + cert: "", + key: "", + }, client: { enable: true, port: "3000", diff --git a/src/lib/config/config.type.ts b/src/lib/config/config.type.ts index 085fa9e..b50435c 100644 --- a/src/lib/config/config.type.ts +++ b/src/lib/config/config.type.ts @@ -93,6 +93,20 @@ export class ServerConfig { dirs!: DirsConfig; } +export class SslConfig { + @Expose() + @IsBoolean() + enable!: boolean; + + @Expose() + @IsString() + cert!: string; + + @Expose() + @IsString() + key!: string; +} + export class Config { @Expose() @IsString() @@ -116,4 +130,9 @@ export class Config { @Type(() => ServerConfig) @ValidateNested() server!: ServerConfig; + + @Expose() + @Type(() => SslConfig) + @ValidateNested() + ssl!: SslConfig; } From 8ac070a83d32d1a01bbbdb5a1b297539aabbe470 Mon Sep 17 00:00:00 2001 From: josephine Date: Wed, 24 Jun 2026 08:56:47 +0200 Subject: [PATCH 2/2] fix: cert and key ternary --- src/action/actions/start.action.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/action/actions/start.action.ts b/src/action/actions/start.action.ts index 2c4c582..2198e37 100644 --- a/src/action/actions/start.action.ts +++ b/src/action/actions/start.action.ts @@ -63,8 +63,8 @@ export class StartAction extends AbstractAction { if (!isSslRequested) return undefined; - const cert = cliCert || config.ssl?.cert; - const key = cliKey || config.ssl?.key; + const cert = cliCert ? cliCert : config.ssl?.cert; + const key = cliKey ? cliKey : config.ssl?.key; if (!cert) { throw new CLIError(