Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions src/action/actions/start.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 ? cliCert : config.ssl?.cert;
const key = cliKey ? 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,
Expand Down
5 changes: 5 additions & 0 deletions src/lib/config/config-defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
19 changes: 19 additions & 0 deletions src/lib/config/config.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -116,4 +130,9 @@ export class Config {
@Type(() => ServerConfig)
@ValidateNested()
server!: ServerConfig;

@Expose()
@Type(() => SslConfig)
@ValidateNested()
ssl!: SslConfig;
}
Loading