elysia-local-https
v1.0.2
Published
[](https://badge.fury.io/js/elysia-local-https)
Maintainers
Readme
mrtcmn/elysia-local-https
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 -installUsage
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|falseHTTPS_CERT_PATH/HTTPS_KEY_PATH(defaults tocerts/local/localhost.pemandcerts/local/localhost-key.pem)domainsoverride in code for mkcert (defaults tolocalhost,127.0.0.1,::1)
When enabled the plugin will:
- Run
mkcert -installto 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.tsBuild
bun install
bun run build