This repository has been archived on 2018-10-12. You can view files and clone it, but cannot push or open issues or pull requests.
ProgBlog/server.js

51 lines
1.2 KiB
JavaScript
Raw Normal View History

2016-02-19 12:58:16 -05:00
'use strict';
const fs = require('fs');
const container = require('./app/Container');
const app = container.get('./bootstrap');
const config = container.get('base/Config');
const HttpServer = container.get('base/HttpServer');
const HttpsServer = container.get('base/HttpsServer');
/**
* Normalize a port into a number, string, or false.
*
* @private
* @param {mixed} val - port value
* @return {mixed} - normalized value
*/
function normalizePort(val) {
let port = parseInt(val, 10);
if (isNaN(port)) {
// named pipe
return val;
}
if (port >= 0) {
// port number
return port;
}
return false;
}
// Create HTTP Server
if (true === config.get('http')) {
let port = normalizePort(config.get('http-port'));
app.set('port', port);
container.set('http-server', new HttpServer(app, port));
}
// Create HTTPs Server
if (true === config.get('https')) {
const httpsPort = normalizePort(config.get('https-port'));
const httpsConfig = {
key: fs.readFileSync(config.get('https-config-key')),
cert: fs.readFileSync(config.get('https-config-cert')),
};
app.set('https-port', httpsPort);
container.set('https-server', new HttpsServer(app, httpsPort, httpsConfig));
}
// End of server.js