bin/www now reads config

- added reading the yaml config to bin/www to configure the port
pull/3/head
Trivernis 5 years ago
parent 02fd2665f2
commit c98c57cfa2

@ -4,22 +4,33 @@
* Module dependencies. * Module dependencies.
*/ */
var app = require('../app'); const app = require('../app');
var debug = require('debug')('whooshy:server'); const debug = require('debug')('whooshy:server');
var http = require('http'); const http = require('http');
const yaml = require('js-yaml');
const fsx = require('fs-extra');
try {
let settings = yaml.safeLoad(fsx.readFileSync('default-config.yaml'));
if (fsx.existsSync('config.yaml'))
Object.assign(settings, yaml.safeLoad(fsx.readFileSync('config.yaml')));
} catch (err) {
console.error(err);
}
/** /**
* Get port from environment and store in Express. * Get port from environment and store in Express.
*/ */
var port = normalizePort(process.env.PORT || '3000'); let port = normalizePort(process.env.PORT || settings.port || '3000');
app.set('port', port); app.set('port', port);
/** /**
* Create HTTP server. * Create HTTP server.
*/ */
var server = http.createServer(app); let server = http.createServer(app);
/** /**
* Listen on provided port, on all network interfaces. * Listen on provided port, on all network interfaces.
@ -34,7 +45,7 @@ server.on('listening', onListening);
*/ */
function normalizePort(val) { function normalizePort(val) {
var port = parseInt(val, 10); let port = parseInt(val, 10);
if (isNaN(port)) { if (isNaN(port)) {
// named pipe // named pipe
@ -58,7 +69,7 @@ function onError(error) {
throw error; throw error;
} }
var bind = typeof port === 'string' let bind = typeof port === 'string'
? 'Pipe ' + port ? 'Pipe ' + port
: 'Port ' + port; : 'Port ' + port;
@ -82,8 +93,8 @@ function onError(error) {
*/ */
function onListening() { function onListening() {
var addr = server.address(); let addr = server.address();
var bind = typeof addr === 'string' let bind = typeof addr === 'string'
? 'pipe ' + addr ? 'pipe ' + addr
: 'port ' + addr.port; : 'port ' + addr.port;
debug('Listening on ' + bind); debug('Listening on ' + bind);

Loading…
Cancel
Save