fastify-cli icon indicating copy to clipboard operation
fastify-cli copied to clipboard

How to configure project to run as https in development mode

Open clluiz opened this issue 2 years ago • 2 comments

HI. I've created a fastify project using fastify-cli but I can't find how to make my local project use https. I already generated the certificates.

When not using fastify-cli I can do this:

const fastify = require("fastify")({
  https: {
    key: fs.readFileSync("path/to/key.pem"),
    cert: fs.readFileSync("path/to/cert.pem"),
  },
});

But I don't see how to do same when using fastify-cli.

clluiz avatar Jan 29 '24 23:01 clluiz

Thanks for reporting! Would you like to send a Pull Request to address this feature? Remember to add unit tests.

mcollina avatar Jan 30 '24 20:01 mcollina

I don't think code changes are needed. You can specify the key and cert as such

const options = {
  https: {
    key: fs.readFileSync("./key.pem"),
    cert: fs.readFileSync("./cert.pem"),
  },
};

in your app.js file generated by the fastify-cli generate command. When you run the fastify start command, pass --options or -o to let fastify uses the above options. Let me know if this solves your questions.

weixinwu avatar Mar 14 '24 06:03 weixinwu