Sails.JS HTTP + HTTPS

后端 未结 8 2216
夕颜
夕颜 2021-01-02 04:49

I am trying to figure out how to lift a sails app that responds to both HTTP and HTTPS requests. I used the config/local.js method of configuring express like so (detailed h

8条回答
  •  礼貌的吻别
    2021-01-02 05:49

    I was able to get http and https running with sails by modifying my configs/local.js file:

    var fs = require('fs');
    var local = ... // Your default local.js settings should go here
    if(require('optimist').argv.https) {
        local.express = {
            serverOptions : {
                key: fs.readFileSync('ssl/server.key'),
                cert: fs.readFileSync('ssl/server.crt')
            }
        };
        local.port = 1338; // This port should be different than your default port
    }
    module.exports = local;
    

    Now you will need to run your sails app twice. The first time type in your regular sails lift command. The second time run sails lift --https

    This should allow you to have both http and https servers running off of the same codebase. As some other people have mentioned, nginx is a much better solution for handling this sort of this, but if you are doing local development and don't want to have to install nginx the solution above is just fine.

提交回复
热议问题