1.0.10 • Published 4 months ago

fastify-acme v1.0.10

Weekly downloads
-
License
ISC
Repository
github
Last release
4 months ago

fastify-acme

Implement ACME protocol (plugin) for Fastify.

Installation

npm install fastify-acme

Register ACME Account

Before running the server, you need to register an ACME account. You can do this by installing the package globally and using the fastify-acme-reg CLI or programmatically by calling registerAcmeAccount.

Using CLI

npm install -g fastify-acme
fastify-acme-reg

Programmatically

import { registerAcmeAccount } from 'fastify-acme'

const certDir = './cert'
const email = 'your-email@example.com'

await registerAcmeAccount(certDir, email)

Usage

HTTP Server Example

import fastify from 'fastify'
import { fastifyAcmeSecurePlugin, fastifyAcmeUnsecurePlugin, getCertAndKey } from 'fastify-acme'

const certDir = './cert'
const domain = 'example.com'

const unsecure = fastify()
unsecure.register(fastifyAcmeUnsecurePlugin, { redirectDomain: domain })

void unsecure.listen({ port: 80 })

const certAndKey = await getCertAndKey(certDir, domain)
const secure = fastify({
    https: {
        key: certAndKey.pkey,
        cert: certAndKey.cert
    }
})
secure.register(fastifyAcmeSecurePlugin, { certDir, domain })

secure.get('/', {}, async (_req, resp) => {
    resp.send('Hello, World!')
})

void secure.listen({ port: 443 })

HTTP/2 Server Example

import fastify from 'fastify'
import { fastifyAcmeSecurePlugin, fastifyAcmeUnsecurePlugin, getCertAndKey } from 'fastify-acme'

const certDir = './cert'
const domain = 'example.com'

const unsecure = fastify()
unsecure.register(fastifyAcmeUnsecurePlugin, { redirectDomain: domain })
void unsecure.listen({ port: 80 })

const certAndKey = await getCertAndKey(certDir, domain)
const secure = fastify({
    http2: true,
    https: {
        allowHTTP1: true,
        key: certAndKey.pkey,
        cert: certAndKey.cert
    }
})
secure.register(fastifyAcmeSecurePlugin, { certDir, domain })

secure.get('/', {}, async (_req, resp) => {
    resp.send('Hello, World!')
})

void secure.listen({ port: 443 })

License

ISC

1.0.10

4 months ago

1.0.9

5 months ago

1.0.8

5 months ago

1.0.7

5 months ago

1.0.6

5 months ago

1.0.5

6 months ago

1.0.4

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago