Created
May 7, 2024 06:48
-
-
Save sylvaindethier/d6d374da4fdfbc75fa4c2a945e5f3f33 to your computer and use it in GitHub Desktop.
Fastify HTTPS server with @anchordotdev/cli
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//@ts-expect-error no declaration files | |
import {createSNICallback} from "anchor-pki/auto-cert/sni-callback"; | |
//@ts-expect-error no declaration files | |
import { TermsOfServiceAcceptor } from "anchor-pki/auto-cert/terms-of-service-acceptor"; | |
import https from "node:https"; | |
import type { FastifyServerFactory } from "fastify"; | |
const serverFactory: FastifyServerFactory = (handler) => { | |
const SNICallback = createSNICallback({ | |
name: 'sni-callback', | |
tosAcceptors: TermsOfServiceAcceptor.createAny(), | |
cacheDir: 'tmp/acme' | |
// The following are defaults | |
// | |
// directoryUrl: process.env.ACME_DIRECTORY_URL, | |
// contact: process.env.ACME_CONTACT, | |
// externalAccountBinding: { | |
// kid: process.env.ACME_KID, | |
// hmacKey: process.env.ACME_HMAC_KEY | |
// }, | |
}); | |
return https.createServer({ SNICallback }, handler); | |
} | |
import Fastify from "fasitify"; | |
import { env } from "node:process"; | |
const fastify = Fastify({ | |
// serverFactory only for local environment, assuming it's when NODE_ENV is "development" | |
...(env["NODE_ENV"] === "development" ? { serverFactory } : {}) | |
serverFactory, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment