bin/www now reads config

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

@ -4,22 +4,33 @@
* Module dependencies.
*/
var app = require('../app');
var debug = require('debug')('whooshy:server');
var http = require('http');
const app = require('../app');
const debug = require('debug')('whooshy:server');
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.
*/
var port = normalizePort(process.env.PORT || '3000');
let port = normalizePort(process.env.PORT || settings.port || '3000');
app.set('port', port);
/**
* Create HTTP server.
*/
var server = http.createServer(app);
let server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
@ -34,7 +45,7 @@ server.on('listening', onListening);
*/
function normalizePort(val) {
var port = parseInt(val, 10);
let port = parseInt(val, 10);
if (isNaN(port)) {
// named pipe
@ -58,7 +69,7 @@ function onError(error) {
throw error;
}
var bind = typeof port === 'string'
let bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;
@ -82,8 +93,8 @@ function onError(error) {
*/
function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
let addr = server.address();
let bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);

Loading…
Cancel
Save