Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/strongloop/loopback-example-ssl
An example to demonstrate how to set up SSL for LoopBack applications
https://github.com/strongloop/loopback-example-ssl
Last synced: 3 months ago
JSON representation
An example to demonstrate how to set up SSL for LoopBack applications
- Host: GitHub
- URL: https://github.com/strongloop/loopback-example-ssl
- Owner: strongloop
- License: other
- Archived: true
- Created: 2014-01-31T17:57:34.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2020-03-05T14:56:28.000Z (over 4 years ago)
- Last Synced: 2024-07-16T05:39:49.266Z (4 months ago)
- Language: JavaScript
- Size: 47.9 KB
- Stars: 69
- Watchers: 31
- Forks: 31
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# loopback-example-ssl
**⚠️ This LoopBack 3 example project is no longer maintained. Please refer to [LoopBack 4 Examples](https://loopback.io/doc/en/lb4/Examples.html) 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
```sh
$ 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`:
```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`:
```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
```sh
$ node ./server/server.js
```
## Open the API explorer[https://localhost:3000/explorer](https://localhost:3000/explorer)
## References
1. [http://nodejs.org/api/https.html](http://nodejs.org/api/https.html)
---
[More LoopBack examples](https://loopback.io/doc/en/lb3/Tutorials-and-examples.html)