An example to demonstrate how to set up SSL for LoopBack applications so you can call the REST APIs using HTTPS.
$ cd loopback-example-ssl/server/private
$ openssl genrsa -out privatekey.pem 1024
$ openssl req -new -key privatekey.pem -out certrequest.csr
$ openssl x509 -req -in certrequest.csr -signkey privatekey.pem -out certificate.pemIn ssl-config.js:
varpath=require('path'),fs=require("fs");exports.privateKey=fs.readFileSync(path.join(__dirname,'./private/privatekey.pem')).toString();exports.certificate=fs.readFileSync(path.join(__dirname,'./private/certificate.pem')).toString();The code is in server/server.js:
varhttps=require('https');varsslConfig=require('./ssl-config');
...
varoptions={key: sslConfig.privateKey,cert: sslConfig.certificate};
...
server.listen(app.get('port'),function(){varbaseUrl=(httpOnly? 'http://' : 'https://')+app.get('host')+':'+app.get('port');app.emit('started',baseUrl);console.log('LoopBack server listening @ %s%s',baseUrl,'/');});returnserver; $ node ./server/server.jshttps://localhost:3000/explorer