Skip to content

SSL only if certificate files exist #5297

Answered by Eomm
AmosSzust asked this question in Q&A
Discussion options

You must be logged in to vote

Is this a coding chellange?

const isHttps = fs.existsSync(".../privkey.pem") && fs.existsSync(".../fullchain.pem")

const fastifyInstance  = Fastify({
  logger: true,
  ajv: {
    customOptions: {
      coerceTypes: false,
    },
  },
  ...(isHttps ? {
    https: {
      key: fs.readFileSync(".../privkey.pem"),
      cert: fs.readFileSync(".../fullchain.pem"),
    },
  } : null)
});

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@AmosSzust
Comment options

Comment options

You must be logged in to vote
1 reply
@Eomm
Comment options

Answer selected by AmosSzust
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
help wanted Help the community by contributing to this issue typescript TypeScript related
3 participants