mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-21 02:29:23 +00:00
refactor(server) start
This commit is contained in:
parent
5f6138d6bb
commit
14ccb90b10
1 changed files with 20 additions and 18 deletions
|
|
@ -52,7 +52,8 @@
|
|||
* @param pProcessing {index, appcache, rest}
|
||||
*/
|
||||
function start(options) {
|
||||
var config = main.config;
|
||||
var redirectServer,
|
||||
config = main.config;
|
||||
|
||||
if (!options)
|
||||
options = {};
|
||||
|
|
@ -99,41 +100,42 @@
|
|||
expressApp = express.getApp(controller);
|
||||
Server = http.createServer(expressApp || controller);
|
||||
|
||||
Server.on('error', Util.log);
|
||||
Server.on('error', Util.log.bind(Util));
|
||||
Server.listen(lPort, lIP);
|
||||
lServerLog(lHTTP, lPort);
|
||||
lSockets(Server);
|
||||
},
|
||||
|
||||
lServerLog = function(pHTTP, pPort) {
|
||||
Util.log('* Server running at ' + pHTTP + lIP + ':' + pPort);
|
||||
lServerLog = function(http, port) {
|
||||
Util.log('* Server running at ' + http + lIP + ':' + port);
|
||||
};
|
||||
/* server mode or testing mode */
|
||||
if (config.server) {
|
||||
if (config.server)
|
||||
if (lSSL) {
|
||||
Util.log('* Redirection http -> https is setted up');
|
||||
lServerLog(lHTTP, lPort);
|
||||
var lRedirectServer = http.createServer( function(pReq, pRes) {
|
||||
var lURL,
|
||||
lHost = pReq.headers.host,
|
||||
lParsed = URL.parse(lHost),
|
||||
lHostName = lParsed.protocol;
|
||||
|
||||
redirectServer = http.createServer(function(req, res) {
|
||||
var url,
|
||||
host = req.headers.host,
|
||||
parsed = url.parse(lHost),
|
||||
hostName = parsed.protocol;
|
||||
|
||||
lURL = lHTTPS + lHostName + lSSLPort + pReq.url;
|
||||
url = lHTTPS + hostName + lSSLPort + req.url;
|
||||
|
||||
main.redirect({
|
||||
response: pRes,
|
||||
url: lURL
|
||||
response: res,
|
||||
url: url
|
||||
});
|
||||
});
|
||||
|
||||
lRedirectServer.listen(lPort, lIP);
|
||||
redirectServer.listen(lPort, lIP);
|
||||
|
||||
Server = https.createServer(lSSL, controller);
|
||||
Server.on('error', function (pError) {
|
||||
Server.on('error', function (error) {
|
||||
Util.log('Could not use https port: ' + lSSLPort);
|
||||
Util.log(pError);
|
||||
lRedirectServer.close();
|
||||
Util.log(error);
|
||||
redirectServer.close();
|
||||
Util.log('* Redirection http -> https removed');
|
||||
lHTTPServer();
|
||||
});
|
||||
|
|
@ -144,7 +146,7 @@
|
|||
lServerLog(lHTTPS, lSSLPort);
|
||||
} else
|
||||
lHTTPServer();
|
||||
} else
|
||||
else
|
||||
Util.log('Cloud Commander testing mode');
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue