GithubHelp home page GithubHelp logo

c0demark / loopback-example-ssl Goto Github PK

View Code? Open in Web Editor NEW

This project forked from strongloop/loopback-example-ssl

0.0 2.0 0.0 37 KB

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

License: Other

JavaScript 100.00%

loopback-example-ssl's Introduction

loopback-example-ssl

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

loopback-example-ssl's People

Contributors

amir-61 avatar rmg avatar superkhau avatar voitau avatar 0candy avatar deniselee avatar hacksparrow avatar sam-github avatar simonhoibm avatar paulomcnally avatar raymondfeng avatar ritch avatar siddhipai avatar

Watchers

James Cloos avatar VIJAY KUMAR avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.