Sails.JS HTTP + HTTPS

后端 未结 8 2251
夕颜
夕颜 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:45

    To have both HTTP & HTTPS, avoiding the redirection way:

    Configure your SSL key & cert and HTTPS port in your /config/env/production.js:

    var fs = require( 'fs' );
    module.exports = {
        port: 443,
        ssl: {
            key: fs.readFileSync( 'ssl_key.key' ),
            cert: fs.readFileSync( 'ssl_key.crt' )
        }
        //, ...
    };
    

    Then, listen port 80 with a second HTTP server into /config/bootstrap.js:

    var http = require( 'http' );
    module.exports.bootstrap = function ( cb ) {
        // ...
        if ( process.env.NODE_ENV == 'production' )
            http.createServer( sails.hooks.http.app ).listen( 80 );
        // ...
    };
    

提交回复
热议问题