Created
May 7, 2024 06:48
-
-
Save sylvaindethier/d6d374da4fdfbc75fa4c2a945e5f3f33 to your computer and use it in GitHub Desktop.
Revisions
-
sylvaindethier created this gist
May 7, 2024 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ //@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, });