fastify-acme
TypeScript icon, indicating that this package has built-in type declarations

1.0.10 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i fastify-acme

Weekly Downloads

3

Version

1.0.10

License

ISC

Unpacked Size

27.8 kB

Total Files

18

Last publish

Collaborators

  • dmaslennikov