Sails.JS HTTP + HTTPS [英] Sails.JS HTTP + HTTPS
本文介绍了Sails.JS HTTP + HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在设法解决如何解除响应HTTP和HTTPS请求的风帆应用程序。我使用配置express的config / local.js方法(详细的这里):
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 here):
var fs = require('fs');
module.exports = {
port: process.env.PORT || 1337,
environment: process.env.NODE_ENV || 'development',
express: { serverOptions : {
key: fs.readFileSync('ssl/key.pem'),
cert: fs.readFileSync('ssl/cert.pem')
}}
};
但是,尽管如此,它只能使服务器 能够提供HTTPS请求。有没有人知道如何完成这项工作,而不会创建一个单独的HTTP服务器,重定向到端口443?
However, while this works, it results in the server only being able to serve HTTPS requests. Has anyone figured out how to get this done, without creating a separate HTTP only server that redirects to port 443 ?
谢谢
推荐答案
要拥有HTTP& HTTPS,避免重定向方式:
配置您的 SSL密钥&
var fs = require( 'fs' );
module.exports = {
port: 443,
ssl: {
key: fs.readFileSync( 'ssl_key.key' ),
cert: fs.readFileSync( 'ssl_key.crt' )
}
//, ...
};
然后,将第一个HTTP服务器的侦听端口80 /config/bootstrap.js:
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 );
// ...
};
这篇关于Sails.JS HTTP + HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文