Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 558
pewpewlasers Avatar asked Jul 08 '26 09:07

pewpewlasers


1 Answers

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.

like image 190
Daniel Avatar answered Jul 10 '26 10:07

Daniel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!