Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Apr 18, 2020. It is now read-only.

strongloop/loopback-example-ssl

Open more actions menu

Repository files navigation

loopback-example-ssl

⚠️ This LoopBack 3 example project is no longer maintained. Please refer to LoopBack 4 Examples instead. ⚠️

An example to demonstrate how to set up SSL for LoopBack applications so you can call the REST APIs using HTTPS.

Generate your own SSL certificate

  $ 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.pem

Load the SSL certificate

In ssl-config.js:

var path = 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();

Create the HTTPS server

The code is in server/server.js:

var https = require('https');
var sslConfig = require('./ssl-config');

...

var options = {
  key: sslConfig.privateKey,
  cert: sslConfig.certificate
};
...

server.listen(app.get('port'), function() {
    var baseUrl = (httpOnly? 'http://' : 'https://') + app.get('host') + ':' + app.get('port');
    app.emit('started', baseUrl);
    console.log('LoopBack server listening @ %s%s', baseUrl, '/');
});
return server;

Start the application

  $  node ./server/server.js

Open the API explorer

https://localhost:3000/explorer

References

  1. http://nodejs.org/api/https.html

More LoopBack examples

About

An example to demonstrate how to set up SSL for LoopBack applications

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Morty Proxy This is a proxified and sanitized view of the page, visit original site.