pewpewlasers
pewpewlasers

Reputation: 3225

Let's encrypt with Sails.js

Has anyone been able to use let's encrypt node module (https://git.coolaj86.com/coolaj86/greenlock-express.js) with Sails.js? A little pointer would be helpful.

Upvotes: 3

Views: 1305

Answers (2)

xoapit
xoapit

Reputation: 1

I had to downgrade green lock to version 2.

Upvotes: 0

Daniel
Daniel

Reputation: 777

Yes, you can use greenlock-express.js for this to achieve SSL with LetsEncrypt directly within the Sails node environment.

The example below:

  1. Configures an HTTP express app using greenlock on port 80 that handles the redirects to HTTPS and the LetsEncrypt business logic.
  2. Uses the greenlock SSL configuration to configure the primary Sails app as HTTPS on port 443.

Sample configuration for config/local.js:

// returns an instance of greenlock.js with additional helper methods
var glx = require('greenlock-express').create({
  server: 'https://acme-v02.api.letsencrypt.org/directory'
  , version: 'draft-11' // Let's Encrypt v2 (ACME v2)
  , telemetry: true
  , servername: 'domainname.com'
  , configDir: '/tmp/acme/'
  , email: '[email protected]'
  , agreeTos: true
  , communityMember: true
  , approveDomains: [ 'domainname.com', 'www.domainname.com' ]
  , debug: true
});

// handles acme-challenge and redirects to https
require('http').createServer(glx.middleware(require('redirect-https')())).listen(80, function () {
  console.log("Listening for ACME http-01 challenges on", this.address());
});

module.exports = {
  port: 443,
  ssl: true,
  http: {
    serverOptions: glx.httpsOptions,
  },
};

Refer to the greenlock documentation for fine-tuning configuration detail, but the above gets an out-of-the-box LetsEncrypt working with Sails.

Note also, that you may wish to place this configuration in somewhere like config/env/production.js as appropriate.

Upvotes: 1

Related Questions