To use HTTPS, you need a key and certificate:
var https_options = { key: fs.readFileSync('/etc/ssl/self-signed/server.key'), certificate: fs.readFileSync('/etc/ssl/self-signed/server.crt') }; var https_server = restify.createServer(https_options);
You will need to start both servers to allow HTTP and HTTPS access:
http_server.listen(80, function() { console.log('%s listening at %s', http_server.name, http_server.url); });. https_server.listen(443, function() { console.log('%s listening at %s', https_server.name, https_server.url); });.
To configure routes to the server, declare the same routes for both servers, redirecting between HTTP and HTTPS as necessary:
http_server.get('/1', function (req, res, next) { res.redirect('https://www.foo.com/1', next); }); https_server.get('/1', function (req, res, next) {
The above listens for requests to the /1 route and simply redirects it to the HTTPS server that processes it.
source share