diff --git a/.changeset/fix-https-env-boolean.md b/.changeset/fix-https-env-boolean.md new file mode 100644 index 0000000..46a04d7 --- /dev/null +++ b/.changeset/fix-https-env-boolean.md @@ -0,0 +1,7 @@ +--- +'maildev': patch +--- + +Parse `MAILDEV_HTTPS` as a boolean (#294). It was passed through as the raw +string, so `MAILDEV_HTTPS=false` still enabled HTTPS and startup failed asking +for `httpsCert` and `httpsKey`. diff --git a/packages/cli/src/__tests__/config/env.test.ts b/packages/cli/src/__tests__/config/env.test.ts index 95b048e..49bc551 100644 --- a/packages/cli/src/__tests__/config/env.test.ts +++ b/packages/cli/src/__tests__/config/env.test.ts @@ -101,6 +101,29 @@ describe('loadEnvConfig', () => { expect(config.basePathname).toBe('/mail/') }) + it('should parse MAILDEV_HTTPS=true as boolean true', () => { + process.env.MAILDEV_HTTPS = 'true' + + const config = loadEnvConfig() + expect(config.https).toBe(true) + }) + + it('should parse MAILDEV_HTTPS=false as boolean false', () => { + process.env.MAILDEV_HTTPS = 'false' + + const config = loadEnvConfig() + expect(config.https).toBe(false) + }) + + it('should load MAILDEV_HTTPS_CERT and MAILDEV_HTTPS_KEY as path strings', () => { + process.env.MAILDEV_HTTPS_CERT = '/ssl/cert.pem' + process.env.MAILDEV_HTTPS_KEY = '/ssl/key.pem' + + const config = loadEnvConfig() + expect(config.httpsCert).toBe('/ssl/cert.pem') + expect(config.httpsKey).toBe('/ssl/key.pem') + }) + it('should ignore invalid port numbers', () => { process.env.MAILDEV_SMTP_PORT = 'not-a-number' diff --git a/packages/cli/src/config/env.ts b/packages/cli/src/config/env.ts index 404d0a5..8ac3e2d 100644 --- a/packages/cli/src/config/env.ts +++ b/packages/cli/src/config/env.ts @@ -145,6 +145,7 @@ function envVarToConfigKey(envVar: string): keyof PartialMailDevConfig | null { webPort: 'web', incomingSecure: 'incomingSecure', outgoingSecure: 'outgoingSecure', + https: 'https', disableWeb: 'disableWeb', verbose: 'verbose', silent: 'silent',