JKHeadley / rest-hapi

🚀 A RESTful API generator for Node.js

Home Page:https://resthapi.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use SSL with rest-hapi?

tuutoo opened this issue · comments

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

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;
}
}
}
})

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