fastify / fastify-cli

Run a Fastify application with one command!
MIT License
644 stars 160 forks source link

How to configure project to run as https in development mode #703

Open clluiz opened 5 months ago

clluiz commented 5 months ago

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.

mcollina commented 5 months ago

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

weixinwu commented 4 months ago

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.