From 280413bf7ebe7e55d906552aa6a282164d190ca6 Mon Sep 17 00:00:00 2001 From: John Furrow Date: Sat, 9 Jul 2016 13:07:40 -0700 Subject: [PATCH] Use user-defined config based on supplied template --- .gitignore | 1 + config.template.js | 16 ++++++++++++++++ server/bin/www | 17 +++++++++++++---- 3 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 config.template.js diff --git a/.gitignore b/.gitignore index 7655b450..4787dab9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .DS_Store +config.js node_modules npm-debug.log server/assets diff --git a/config.template.js b/config.template.js new file mode 100644 index 00000000..4d8ead72 --- /dev/null +++ b/config.template.js @@ -0,0 +1,16 @@ +const config = { + dbCleanInterval: 1000 * 60 * 60, + dbPath: './server/db/', + floodServerPort: 3000, + maxHistoryStates: 30, + pollInterval: 1000 * 5, + secret: 'flood', + scgi: { + host: 'localhost', + port: 5000, + socket: false, + socketPath: '/tmp/rtorrent.sock' + } +}; + +module.exports = config; diff --git a/server/bin/www b/server/bin/www index 25fd22ca..f39350f9 100755 --- a/server/bin/www +++ b/server/bin/www @@ -1,10 +1,19 @@ #!/usr/bin/env node -/** - * Module dependencies. - */ +'use strict'; + +// Ensure we have a user-defined config.js for use throughout the app. +try { + let fs = require('fs'); + fs.accessSync('./config.js', fs.F_OK); +} catch (e) { + console.error('Cannot start Flood server, config.js is missing. Copy ' + + 'config.template.js to config.js.'); + return; +} var app = require('../app'); +let config = require('../../config'); var debug = require('debug')('flood:server'); var http = require('http'); @@ -12,7 +21,7 @@ var http = require('http'); * Get port from environment and store in Express. */ -var port = normalizePort(process.env.PORT || '3000'); +var port = normalizePort(config.floodServerPort); app.set('port', port); /**