Skip to content

mrtcmn/elysia-local-https

Repository files navigation

mrtcmn/elysia-local-https

npm version

Auto-configure local HTTPS for Elysia/Bun apps using mkcert. The plugin handles creating and refreshing certificates locally so your app.listen call can stay minimal.

Install mkcert once

brew install mkcert nss
mkcert -install

Usage

import { Elysia } from 'elysia'
import { localHttps } from 'elysia-local-https'

const app = new Elysia().get('/', () => 'secure ✅')

app.listen(localHttps({ port: 3000 }))

By default local HTTPS is enabled when NODE_ENV !== 'production'. Control via env vars or overrides:

  • ENABLE_LOCAL_HTTPS=true|false
  • HTTPS_CERT_PATH / HTTPS_KEY_PATH (defaults to certs/local/localhost.pem and certs/local/localhost-key.pem)
  • domains override in code for mkcert (defaults to localhost, 127.0.0.1, ::1)

When enabled the plugin will:

  • Run mkcert -install to ensure the local root CA is trusted.
  • Generate missing cert/key files with mkcert.
  • Refresh the cert when <14 days from expiry.
  • Log a concise hint with errors and the exact mkcert command if something fails.

When you are running first time your app:

  • Script may prompt sudo password for mkdir -install command.
  • If you are not allowed sudo access, you can call manualy. Don't forget to restart your app.

Options

localHttps method first argument is same as listen() command argument.

localHttps(options, {
  enabled: true,               // or false, defaults to NODE_ENV !== 'production'
  certPath: 'certs/local/localhost.pem',
  keyPath: 'certs/local/localhost-key.pem',
  domains: ['localhost', '127.0.0.1', '::1']
})

Example

ENABLE_LOCAL_HTTPS=true bun example/index.ts

Build

bun install
bun run build

About

Automatic local HTTPS for Elysia — certs generated, managed, and refreshed in one line.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published