JKHeadley / rest-hapi

🚀 A RESTful API generator for Node.js
https://resthapi.com
MIT License
1.19k stars 153 forks source link

How to use SSL with rest-hapi? #246

Closed tuutoo closed 4 years ago

tuutoo commented 4 years ago

Is it possible start the server with https protocol? I have my SSL certificates but don't know how to configure to use https.

tuutoo commented 4 years ago

I have found a solution and it works now. :D

in api.js

  1. at the beginning, add 1 line to require fs module.
  2. add a tls node in below section.

const fs = require('fs') ... ... let server = Hapi.Server({ port: 3001, tls: { key: fs.readFileSync('/your_ssl_key_path/privkey.pem'), cert: fs.readFileSync('/your_ssl_key_path/fullchain.pem') }, routes: { validate: { failAction: async (request, h, err) => { RestHapi.logger.error(err); throw err; } } } })

JKHeadley commented 4 years ago

@tuutoo glad you worked it out. Thanks for sharing! ;)