Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to configure https in sails.js

I am trying to setup a local HTTPS server for testing in Sails.js? I am not able to find any pointer how to do that in sails.js? For express,

var express = require('express');
var https = require('https');
var http = require('http');
var fs = require('fs');

// This line is from the Node.js HTTPS documentation.
var options = {
  key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
  cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem')
};

// Create a service (the app object is just a callback).
var app = express();

// Create an HTTP service.
http.createServer(app).listen(80);
// Create an HTTPS service identical to the HTTP service.
https.createServer(options, app).listen(443);

Any idea about sails.js?

like image 986
lostShip Avatar asked Jul 19 '13 21:07

lostShip


2 Answers

For sails.js version 0.10, include this in config/locals.js (if locals.js does not exist, create it):

var fs = require('fs');

module.exports = {

    ssl : {
        key: fs.readFileSync('path-to-key.key'),
       cert: fs.readFileSync('path-to-crt.crt')
    }

};

Source: https://stackoverflow.com/a/28565113/2459071

like image 103
JosMarRivera Avatar answered Oct 19 '22 15:10

JosMarRivera


If you're using the latest v0.9 (and maybe some versions of v0.8) take look inside of config/bootstrap.js. You should be able to access your express app via the sails.express context. From there I think you should be able to do with it what you want to...

Also someone in the #sailsjs irc channel said this worked for them

module.exports.bootstrap = function (cb) {
    var fs = require('fs');
    sails.config.express.serverOptions = {
        key: fs.readFileSync('ssl/key.pem'),
        cert: fs.readFileSync('ssl/cert.pem')
    };
    cb();
};
like image 30
Kelt Dockins Avatar answered Oct 19 '22 15:10

Kelt Dockins