@simplens/onboard 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplens/onboard",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -28,12 +28,14 @@ describe('promptInfraServicesWithBasePath', () => {
28
28
  const mockMultiselect = vi.mocked(multiselect);
29
29
  mockMultiselect.mockResolvedValue(['mongo', 'redis', 'nginx']);
30
30
 
31
- const result = await promptInfraServicesWithBasePath({ allowNginx: true });
31
+ const result = await promptInfraServicesWithBasePath({ allowNginx: true, defaultNginx: true });
32
32
 
33
33
  // Should include nginx in options
34
34
  const callArgs = mockMultiselect.mock.calls[0][0] as any;
35
35
  const values = callArgs.options.map((o: any) => o.value);
36
36
  expect(values).toContain('nginx');
37
+ expect(callArgs.initialValues).toContain('nginx');
38
+ expect(callArgs.initialValues).not.toContain('kafka-ui');
37
39
 
38
40
  expect(result).toContain('nginx');
39
41
  });
@@ -12,4 +12,19 @@ describe('infra app compose generation', () => {
12
12
  expect(compose).toContain(' nginx:');
13
13
  expect(compose).toContain('./nginx.conf:/etc/nginx/conf.d/default.conf:ro');
14
14
  });
15
+
16
+ it('does not include certbot services when ssl is disabled', () => {
17
+ const compose = buildAppComposeContent(true, { includeSsl: false });
18
+ expect(compose).not.toContain(' certbot:');
19
+ expect(compose).not.toContain(' certbot-renew:');
20
+ });
21
+
22
+ it('includes certbot services and volumes when ssl is enabled', () => {
23
+ const compose = buildAppComposeContent(false, { includeSsl: true });
24
+ expect(compose).toContain(' nginx:');
25
+ expect(compose).toContain(' certbot:');
26
+ expect(compose).toContain(' certbot-renew:');
27
+ expect(compose).toContain('certbot-etc:');
28
+ expect(compose).toContain('certbot-www:');
29
+ });
15
30
  });
@@ -4,7 +4,9 @@ import {
4
4
  checkDockerRunning,
5
5
  detectOS,
6
6
  validatePrerequisites,
7
- validateEnvValue
7
+ validateEnvValue,
8
+ validatePublicDomain,
9
+ validateEmailAddress
8
10
  } from '../validators.js';
9
11
  import {
10
12
  DockerNotInstalledError,
@@ -192,4 +194,28 @@ describe('validators', () => {
192
194
  });
193
195
  });
194
196
  });
197
+
198
+ describe('validatePublicDomain', () => {
199
+ it('accepts valid public domains', () => {
200
+ expect(validatePublicDomain('example.com')).toBe(true);
201
+ expect(validatePublicDomain('app.example.com')).toBe(true);
202
+ });
203
+
204
+ it('rejects urls or malformed values', () => {
205
+ expect(validatePublicDomain('https://example.com')).not.toBe(true);
206
+ expect(validatePublicDomain('example')).not.toBe(true);
207
+ expect(validatePublicDomain('example.com/path')).not.toBe(true);
208
+ });
209
+ });
210
+
211
+ describe('validateEmailAddress', () => {
212
+ it('accepts valid email addresses', () => {
213
+ expect(validateEmailAddress('admin@example.com')).toBe(true);
214
+ });
215
+
216
+ it('rejects invalid email values', () => {
217
+ expect(validateEmailAddress('admin@')).not.toBe(true);
218
+ expect(validateEmailAddress('not-an-email')).not.toBe(true);
219
+ });
220
+ });
195
221
  });
package/src/index.ts CHANGED
@@ -15,7 +15,11 @@ import {
15
15
  } from './utils.js';
16
16
  import { text, confirm, select } from '@clack/prompts';
17
17
  import { intro, outro, handleCancel, log, note } from './ui.js';
18
- import { validatePrerequisites } from './validators.js';
18
+ import {
19
+ validatePrerequisites,
20
+ validatePublicDomain,
21
+ validateEmailAddress,
22
+ } from './validators.js';
19
23
  import {
20
24
  promptInfraServicesWithBasePath,
21
25
  generateInfraCompose,
@@ -45,6 +49,8 @@ import {
45
49
  waitForInfraHealth,
46
50
  startAppServices,
47
51
  displayServiceStatus,
52
+ setupSslCertificates,
53
+ getSslManualCommands,
48
54
  } from './services.js';
49
55
 
50
56
  const program = new Command();
@@ -61,6 +67,9 @@ program
61
67
  .option('--core-version <version>', 'Override CORE_VERSION in generated .env (primarily for --full mode)')
62
68
  .option('--dashboard-version <version>', 'Override DASHBOARD_VERSION in generated .env (primarily for --full mode)')
63
69
  .option('--plugin [plugins...]', 'Plugins to install (e.g., @simplens/mock @simplens/nodemailer-gmail)')
70
+ .option('--ssl', 'Enable optional SSL certificate setup using Dockerized Certbot')
71
+ .option('--ssl-domain <domain>', 'Public domain for SSL certificate (required with --ssl in --full mode)')
72
+ .option('--ssl-email <email>', 'Email for Let\'s Encrypt registration (required with --ssl in --full mode)')
64
73
  .option('--no-output', 'Suppress all console output (silent mode)');
65
74
 
66
75
  interface OnboardSetupOptions {
@@ -70,6 +79,9 @@ interface OnboardSetupOptions {
70
79
  targetDir: string;
71
80
  basePath: string;
72
81
  plugins: string[];
82
+ enableSsl: boolean;
83
+ sslDomain?: string;
84
+ sslEmail?: string;
73
85
  }
74
86
 
75
87
  function printStep(step: number, total: number, title: string): void {
@@ -112,6 +124,9 @@ function showSetupSummary(setupOptions: OnboardSetupOptions, targetDir: string,
112
124
  const pluginsLabel = setupOptions.plugins.length > 0
113
125
  ? setupOptions.plugins.join(', ')
114
126
  : 'none';
127
+ const sslLabel = setupOptions.enableSsl
128
+ ? `enabled (${setupOptions.sslDomain})`
129
+ : 'disabled';
115
130
 
116
131
  const summaryLines = [
117
132
  `Target directory : ${targetDir}`,
@@ -119,6 +134,7 @@ function showSetupSummary(setupOptions: OnboardSetupOptions, targetDir: string,
119
134
  `Environment mode : ${setupOptions.envMode}`,
120
135
  `BASE_PATH : ${basePathLabel}`,
121
136
  `Plugins : ${pluginsLabel}`,
137
+ `SSL (Certbot) : ${sslLabel}`,
122
138
  `Nginx auto-include : ${autoNginx ? 'enabled (BASE_PATH is non-default)' : 'disabled'}`,
123
139
  ].join('\n');
124
140
 
@@ -170,6 +186,26 @@ async function promptSetupOptions(options: any): Promise<OnboardSetupOptions> {
170
186
  }
171
187
  }
172
188
 
189
+ if (options.ssl === true) {
190
+ if (!options.sslDomain) {
191
+ errors.push('--ssl-domain <domain> is required in --full mode when --ssl is enabled');
192
+ } else {
193
+ const domainValidation = validatePublicDomain(options.sslDomain);
194
+ if (domainValidation !== true) {
195
+ errors.push(`Invalid --ssl-domain: ${domainValidation}`);
196
+ }
197
+ }
198
+
199
+ if (!options.sslEmail) {
200
+ errors.push('--ssl-email <email> is required in --full mode when --ssl is enabled');
201
+ } else {
202
+ const emailValidation = validateEmailAddress(options.sslEmail);
203
+ if (emailValidation !== true) {
204
+ errors.push(`Invalid --ssl-email: ${emailValidation}`);
205
+ }
206
+ }
207
+ }
208
+
173
209
  if (errors.length > 0) {
174
210
  console.error('\\n❌ Validation errors in --full mode:\\n');
175
211
  errors.forEach(err => console.error(` • ${err}`));
@@ -274,6 +310,55 @@ async function promptSetupOptions(options: any): Promise<OnboardSetupOptions> {
274
310
  }
275
311
  // If not provided and not in full mode, will prompt later in the main workflow
276
312
 
313
+ // --- SSL ---
314
+ let enableSslValue = false;
315
+ let sslDomainValue: string | undefined;
316
+ let sslEmailValue: string | undefined;
317
+
318
+ if (options.ssl === true) {
319
+ enableSslValue = true;
320
+ } else if (!isFullMode) {
321
+ const sslConfirm = await confirm({
322
+ message: 'Do you want to automatically setup SSL certificate using Certbot?',
323
+ initialValue: false,
324
+ withGuide: true,
325
+ });
326
+ handleCancel(sslConfirm);
327
+ enableSslValue = sslConfirm as boolean;
328
+ }
329
+
330
+ if (enableSslValue) {
331
+ if (typeof options.sslDomain === 'string') {
332
+ sslDomainValue = options.sslDomain.trim().toLowerCase();
333
+ } else if (!isFullMode) {
334
+ const domainAnswer = await text({
335
+ message: 'Public domain to secure (example: app.example.com):',
336
+ validate: (value: string | undefined) => {
337
+ const validation = validatePublicDomain(value ?? '');
338
+ return validation === true ? undefined : validation;
339
+ },
340
+ withGuide: true,
341
+ });
342
+ handleCancel(domainAnswer);
343
+ sslDomainValue = (domainAnswer as string).trim().toLowerCase();
344
+ }
345
+
346
+ if (typeof options.sslEmail === 'string') {
347
+ sslEmailValue = options.sslEmail.trim();
348
+ } else if (!isFullMode) {
349
+ const emailAnswer = await text({
350
+ message: 'Email for Let\'s Encrypt registration:',
351
+ validate: (value: string | undefined) => {
352
+ const validation = validateEmailAddress(value ?? '');
353
+ return validation === true ? undefined : validation;
354
+ },
355
+ withGuide: true,
356
+ });
357
+ handleCancel(emailAnswer);
358
+ sslEmailValue = (emailAnswer as string).trim();
359
+ }
360
+ }
361
+
277
362
  return {
278
363
  infra: infraValue,
279
364
  infraServices: infraServices,
@@ -281,6 +366,9 @@ async function promptSetupOptions(options: any): Promise<OnboardSetupOptions> {
281
366
  targetDir: targetDirValue || process.cwd(),
282
367
  basePath: basePathValue,
283
368
  plugins: pluginsValue,
369
+ enableSsl: enableSslValue,
370
+ sslDomain: sslDomainValue,
371
+ sslEmail: sslEmailValue,
284
372
  };
285
373
  }
286
374
 
@@ -318,6 +406,7 @@ async function main() {
318
406
  // Get target directory
319
407
  const targetDir = path.resolve(setupOptions.targetDir);
320
408
  const autoEnableNginx = shouldAutoEnableNginx(setupOptions.basePath);
409
+ const nginxRequired = autoEnableNginx || setupOptions.enableSsl;
321
410
 
322
411
  logDebug(`Resolved target directory: ${targetDir}`);
323
412
  showSetupSummary(setupOptions, targetDir, autoEnableNginx);
@@ -329,39 +418,50 @@ async function main() {
329
418
  // Step 2: Infrastructure setup (if --infra flag is provided)
330
419
  log.step('Step 2/6 — Infrastructure Setup');
331
420
  let selectedInfraServices: string[] = [];
421
+ const shouldSetupInfra = setupOptions.infra || nginxRequired;
332
422
 
333
- if (setupOptions.infra) {
423
+ if (shouldSetupInfra) {
334
424
  // Use pre-provided services from CLI, or prompt for them
335
- if (setupOptions.infraServices.length > 0) {
425
+ if (setupOptions.infra && setupOptions.infraServices.length > 0) {
336
426
  selectedInfraServices = setupOptions.infraServices;
337
427
  log.info(`Using infrastructure services: ${selectedInfraServices.join(', ')}`);
428
+ } else if (!setupOptions.infra && nginxRequired) {
429
+ selectedInfraServices = ['nginx'];
430
+ log.info('Nginx is required (BASE_PATH/SSL), so infrastructure compose will be generated with nginx.');
338
431
  } else {
339
432
  // Prompt for services (interactive mode)
340
433
  if (!autoEnableNginx) {
341
434
  log.info('BASE_PATH is empty, nginx reverse proxy is disabled.');
342
- selectedInfraServices = await promptInfraServicesWithBasePath({ allowNginx: false });
435
+ selectedInfraServices = await promptInfraServicesWithBasePath({
436
+ allowNginx: false,
437
+ });
343
438
  } else {
344
- selectedInfraServices = await promptInfraServicesWithBasePath({ allowNginx: true });
439
+ selectedInfraServices = await promptInfraServicesWithBasePath({
440
+ allowNginx: true,
441
+ defaultNginx: true,
442
+ });
345
443
  }
346
444
  }
347
445
 
348
- if (autoEnableNginx && !selectedInfraServices.includes('nginx')) {
446
+ if (setupOptions.enableSsl && !selectedInfraServices.includes('nginx')) {
349
447
  selectedInfraServices.push('nginx');
350
- log.info('BASE_PATH is non-default, so nginx was added automatically.');
448
+ log.info('SSL is enabled, so nginx was added automatically.');
351
449
  }
352
450
 
353
- await generateInfraCompose(targetDir, selectedInfraServices);
451
+ const infraHasNginx = selectedInfraServices.includes('nginx');
452
+ await generateInfraCompose(targetDir, selectedInfraServices, {
453
+ includeSsl: setupOptions.enableSsl && infraHasNginx,
454
+ });
354
455
  } else {
355
456
  log.info('Skipping infrastructure setup (use --infra to enable).');
356
457
  }
357
458
 
358
459
  // Step 3: Always write app docker-compose
359
460
  log.step('Step 3/6 — Application Compose Setup');
360
- const includeNginxInAppCompose = autoEnableNginx && !selectedInfraServices.includes('nginx');
361
- if (includeNginxInAppCompose) {
362
- log.info('Including nginx in docker-compose.yaml because BASE_PATH is non-default.');
363
- }
364
- await writeAppCompose(targetDir, { includeNginx: includeNginxInAppCompose });
461
+ await writeAppCompose(targetDir, {
462
+ includeNginx: false,
463
+ includeSsl: false,
464
+ });
365
465
 
366
466
  // Step 4: Environment configuration
367
467
  log.step('Step 4/6 — Environment Configuration');
@@ -390,9 +490,12 @@ async function main() {
390
490
  }
391
491
 
392
492
  // Generate nginx.conf whenever nginx is active in either compose file
393
- const nginxEnabled = selectedInfraServices.includes('nginx') || includeNginxInAppCompose;
493
+ const nginxEnabled = selectedInfraServices.includes('nginx');
394
494
  if (nginxEnabled) {
395
- await generateNginxConfig(targetDir, setupOptions.basePath);
495
+ await generateNginxConfig(targetDir, setupOptions.basePath, {
496
+ enableSsl: setupOptions.enableSsl,
497
+ domain: setupOptions.sslDomain,
498
+ });
396
499
  }
397
500
 
398
501
  // Step 5: Plugin installation
@@ -447,7 +550,7 @@ async function main() {
447
550
 
448
551
  if (shouldStart) {
449
552
  // Start infra services first (if --infra was used)
450
- if (setupOptions.infra && selectedInfraServices.length > 0) {
553
+ if (selectedInfraServices.length > 0) {
451
554
  await startInfraServices(targetDir);
452
555
  await waitForInfraHealth(targetDir);
453
556
  }
@@ -455,15 +558,30 @@ async function main() {
455
558
  // Start app services
456
559
  await startAppServices(targetDir);
457
560
 
561
+ if (setupOptions.enableSsl && setupOptions.sslDomain && setupOptions.sslEmail) {
562
+ await setupSslCertificates(targetDir, {
563
+ composeFile: 'docker-compose.infra.yaml',
564
+ domain: setupOptions.sslDomain,
565
+ email: setupOptions.sslEmail,
566
+ });
567
+ }
568
+
458
569
  // Display service status
459
570
  await displayServiceStatus();
460
571
  } else {
461
572
  log.info('Services not started. You can start them later with:');
462
573
  const commands: string[] = [];
463
- if (setupOptions.infra) {
574
+ if (selectedInfraServices.length > 0) {
464
575
  commands.push('docker-compose -f docker-compose.infra.yaml up -d');
465
576
  }
466
577
  commands.push('docker-compose up -d');
578
+ if (setupOptions.enableSsl && setupOptions.sslDomain && setupOptions.sslEmail) {
579
+ commands.push(...getSslManualCommands({
580
+ composeFile: 'docker-compose.infra.yaml',
581
+ domain: setupOptions.sslDomain,
582
+ email: setupOptions.sslEmail,
583
+ }));
584
+ }
467
585
  printCommandHints('Manual startup commands', commands);
468
586
  }
469
587
 
package/src/infra.ts CHANGED
@@ -1,4 +1,11 @@
1
- import { APP_COMPOSE_TEMPLATE, APP_NGINX_SERVICE_TEMPLATE } from './templates.js';
1
+ import {
2
+ APP_COMPOSE_TEMPLATE,
3
+ APP_NGINX_SERVICE_TEMPLATE,
4
+ APP_NGINX_SSL_SERVICE_TEMPLATE,
5
+ APP_CERTBOT_SERVICES_TEMPLATE,
6
+ INFRA_CERTBOT_SERVICES_TEMPLATE,
7
+ INFRA_CERTBOT_VOLUMES,
8
+ } from './templates.js';
2
9
  import { writeFile, logInfo, logSuccess } from './utils.js';
3
10
  import { multiselect } from '@clack/prompts';
4
11
  import { handleCancel, spinner } from './ui.js';
@@ -8,7 +15,7 @@ import type { InfraService } from './types/domain.js';
8
15
  const INFRA_SERVICES: InfraService[] = [
9
16
  { name: 'MongoDB (Database)', value: 'mongo', checked: true },
10
17
  { name: 'Kafka (Message Queue)', value: 'kafka', checked: true },
11
- { name: 'Kafka UI (Dashboard)', value: 'kafka-ui', checked: true },
18
+ { name: 'Kafka UI (Dashboard)', value: 'kafka-ui', checked: false },
12
19
  { name: 'Redis (Cache)', value: 'redis', checked: true },
13
20
  { name: 'Nginx (Reverse Proxy)', value: 'nginx', checked: false },
14
21
  { name: 'Loki (Log Aggregation)', value: 'loki', checked: false },
@@ -31,9 +38,15 @@ export async function promptInfraServices(): Promise<string[]> {
31
38
  */
32
39
  export async function promptInfraServicesWithBasePath(options: {
33
40
  allowNginx: boolean;
41
+ defaultNginx?: boolean;
34
42
  }): Promise<string[]> {
35
43
  const choices = options.allowNginx
36
- ? INFRA_SERVICES
44
+ ? INFRA_SERVICES.map(service => {
45
+ if (service.value === 'nginx') {
46
+ return { ...service, checked: options.defaultNginx === true };
47
+ }
48
+ return service;
49
+ })
37
50
  : INFRA_SERVICES.filter(service => service.value !== 'nginx');
38
51
 
39
52
  const message = options.allowNginx
@@ -179,6 +192,18 @@ const SERVICE_CHUNKS: Record<string, string> = {
179
192
  restart: unless-stopped`,
180
193
  };
181
194
 
195
+ const NGINX_INFRA_SSL_SERVICE_CHUNK = ` nginx:
196
+ image: nginx:alpine
197
+ container_name: nginx
198
+ ports:
199
+ - "80:80"
200
+ - "443:443"
201
+ volumes:
202
+ - "./nginx.conf:/etc/nginx/conf.d/default.conf:ro"
203
+ - certbot-etc:/etc/letsencrypt
204
+ - certbot-www:/var/www/certbot
205
+ restart: unless-stopped`;
206
+
182
207
  /**
183
208
  * Service-to-volumes mapping
184
209
  */
@@ -195,7 +220,10 @@ const SERVICE_VOLUMES: Record<string, string[]> = {
195
220
  /**
196
221
  * Build docker-compose content from selected services
197
222
  */
198
- function buildInfraCompose(selectedServices: string[]): string {
223
+ function buildInfraCompose(
224
+ selectedServices: string[],
225
+ options: { includeSsl?: boolean } = {}
226
+ ): string {
199
227
  // Header
200
228
  const header = `# ============================================
201
229
  # SimpleNS Infrastructure Services
@@ -212,9 +240,17 @@ services:
212
240
  const serviceBlocks: string[] = [];
213
241
  for (const service of selectedServices) {
214
242
  if (SERVICE_CHUNKS[service]) {
215
- serviceBlocks.push(SERVICE_CHUNKS[service]);
243
+ if (service === 'nginx' && options.includeSsl === true) {
244
+ serviceBlocks.push(NGINX_INFRA_SSL_SERVICE_CHUNK);
245
+ } else {
246
+ serviceBlocks.push(SERVICE_CHUNKS[service]);
247
+ }
216
248
  }
217
249
  }
250
+
251
+ if (options.includeSsl === true) {
252
+ serviceBlocks.push(INFRA_CERTBOT_SERVICES_TEMPLATE);
253
+ }
218
254
 
219
255
  // Collect volumes for selected services
220
256
  const volumeSet = new Set<string>();
@@ -222,6 +258,12 @@ services:
222
258
  const volumes = SERVICE_VOLUMES[service] || [];
223
259
  volumes.forEach(v => volumeSet.add(v));
224
260
  }
261
+
262
+ if (options.includeSsl === true) {
263
+ for (const volumeName of INFRA_CERTBOT_VOLUMES) {
264
+ volumeSet.add(volumeName);
265
+ }
266
+ }
225
267
 
226
268
  // Build volumes section
227
269
  const volumeLines: string[] = ['', 'volumes:'];
@@ -248,13 +290,14 @@ services:
248
290
  */
249
291
  export async function generateInfraCompose(
250
292
  targetDir: string,
251
- selectedServices: string[]
293
+ selectedServices: string[],
294
+ options: { includeSsl?: boolean } = {}
252
295
  ): Promise<void> {
253
296
  const s = spinner();
254
297
  s.start('Generating docker-compose.infra.yaml...');
255
298
 
256
299
  // Build compose content from service chunks
257
- const infraContent = buildInfraCompose(selectedServices);
300
+ const infraContent = buildInfraCompose(selectedServices, options);
258
301
 
259
302
  // Write infrastructure compose file
260
303
  const infraPath = path.join(targetDir, 'docker-compose.infra.yaml');
@@ -266,17 +309,35 @@ export async function generateInfraCompose(
266
309
  * Build app docker-compose content.
267
310
  * Optionally inject nginx reverse-proxy service before the volumes section.
268
311
  */
269
- export function buildAppComposeContent(includeNginx: boolean): string {
270
- if (!includeNginx) {
271
- return APP_COMPOSE_TEMPLATE;
312
+ export function buildAppComposeContent(
313
+ includeNginx: boolean,
314
+ options: { includeSsl?: boolean } = {}
315
+ ): string {
316
+ let content = APP_COMPOSE_TEMPLATE;
317
+ const includeSsl = options.includeSsl === true;
318
+ const shouldIncludeNginx = includeNginx || includeSsl;
319
+ const marker = '\nvolumes:';
320
+
321
+ if (!content.includes(marker)) {
322
+ return content;
272
323
  }
273
324
 
274
- const marker = '\nvolumes:';
275
- if (!APP_COMPOSE_TEMPLATE.includes(marker)) {
276
- return APP_COMPOSE_TEMPLATE;
325
+ if (shouldIncludeNginx) {
326
+ const nginxBlock = includeSsl
327
+ ? APP_NGINX_SSL_SERVICE_TEMPLATE
328
+ : APP_NGINX_SERVICE_TEMPLATE;
329
+ content = content.replace(marker, `\n${nginxBlock}\n${marker}`);
330
+ }
331
+
332
+ if (includeSsl) {
333
+ content = content.replace(marker, `\n${APP_CERTBOT_SERVICES_TEMPLATE}\n${marker}`);
334
+ content = content.replace(
335
+ '\nvolumes:\n plugin-data:',
336
+ '\nvolumes:\n certbot-etc:\n certbot-www:\n plugin-data:'
337
+ );
277
338
  }
278
339
 
279
- return APP_COMPOSE_TEMPLATE.replace(marker, `\n${APP_NGINX_SERVICE_TEMPLATE}\n${marker}`);
340
+ return content;
280
341
  }
281
342
 
282
343
  /**
@@ -284,12 +345,14 @@ export function buildAppComposeContent(includeNginx: boolean): string {
284
345
  */
285
346
  export async function writeAppCompose(
286
347
  targetDir: string,
287
- options: { includeNginx?: boolean } = {}
348
+ options: { includeNginx?: boolean; includeSsl?: boolean } = {}
288
349
  ): Promise<void> {
289
350
  const s = spinner();
290
351
  s.start('Generating docker-compose.yaml...');
291
352
  const appPath = path.join(targetDir, 'docker-compose.yaml');
292
- const appContent = buildAppComposeContent(options.includeNginx === true);
353
+ const appContent = buildAppComposeContent(options.includeNginx === true, {
354
+ includeSsl: options.includeSsl === true,
355
+ });
293
356
  await writeFile(appPath, appContent);
294
357
  s.stop('Generated docker-compose.yaml');
295
358
  }
@@ -299,7 +362,8 @@ export async function writeAppCompose(
299
362
  */
300
363
  export async function generateNginxConfig(
301
364
  targetDir: string,
302
- basePath: string
365
+ basePath: string,
366
+ options: { enableSsl?: boolean; domain?: string } = {}
303
367
  ): Promise<void> {
304
368
  const s = spinner();
305
369
  s.start('Generating nginx.conf...');
@@ -307,12 +371,10 @@ export async function generateNginxConfig(
307
371
  // Normalize basePath (remove leading/trailing slashes for template)
308
372
  const normalizedPath = basePath.trim().replace(/^\/|\/$/g, '');
309
373
  const hasBasePath = normalizedPath.length > 0;
374
+ const enableSsl = options.enableSsl === true;
375
+ const domain = options.domain?.trim() || 'localhost';
310
376
 
311
- // Template for nginx.conf
312
- const nginxTemplate = `server {
313
- listen 80;
314
- server_name localhost;
315
-
377
+ const proxyRoutes = `
316
378
  location /api {
317
379
  proxy_pass http://api:3000;
318
380
  proxy_http_version 1.1;
@@ -395,10 +457,44 @@ ${hasBasePath ? `
395
457
  proxy_set_header X-Forwarded-Proto $scheme;
396
458
  }
397
459
  `}
460
+ `;
461
+
462
+ const nginxTemplate = enableSsl
463
+ ? `server {
464
+ listen 80;
465
+ server_name ${domain};
466
+
467
+ location /.well-known/acme-challenge/ {
468
+ root /var/www/certbot;
469
+ }
470
+
471
+ location / {
472
+ return 301 https://$host$request_uri;
473
+ }
474
+ }
475
+
476
+ server {
477
+ listen 443 ssl;
478
+ server_name ${domain};
479
+
480
+ ssl_certificate /etc/letsencrypt/live/${domain}/fullchain.pem;
481
+ ssl_certificate_key /etc/letsencrypt/live/${domain}/privkey.pem;
482
+ ssl_protocols TLSv1.2 TLSv1.3;
483
+ ssl_prefer_server_ciphers on;
484
+ location = / {
485
+ return 302 /dashboard;
486
+ }
487
+ ${proxyRoutes}
488
+ }
489
+ `
490
+ : `server {
491
+ listen 80;
492
+ server_name localhost;${proxyRoutes}
398
493
  }
399
494
  `;
400
495
 
401
496
  const nginxPath = path.join(targetDir, 'nginx.conf');
402
497
  await writeFile(nginxPath, nginxTemplate);
403
- s.stop(`Generated nginx.conf${hasBasePath ? ` with base path: /${normalizedPath}` : ' (root path)'}`);
498
+ const sslLabel = enableSsl ? `, SSL domain: ${domain}` : '';
499
+ s.stop(`Generated nginx.conf${hasBasePath ? ` with base path: /${normalizedPath}` : ' (root path)'}${sslLabel}`);
404
500
  }