Clarify that secrets are optional

- Quit witih an error when secrets can’t be loaded
- Refactor duplicated code

Resolves #894
This commit is contained in:
Paul Melnikow 2017-03-29 17:27:55 -04:00 committed by Thaddée Tyl
parent 9e4476d1b6
commit c7c92f12fd
3 changed files with 20 additions and 16 deletions

18
lib/server-secrets.js Normal file
View File

@ -0,0 +1,18 @@
// Everything that cannot be checked in but is useful server-side is stored in
// a JSON data file: private/secret.json.
const fs = require('fs');
const path = require('path');
const secretsPath = path.join(__dirname, '..', 'private', 'secret.json');
if (fs.existsSync(secretsPath)) {
try {
module.exports = require(secretsPath);
} catch(e) {
console.error(`Error loading secret data: ${e.message}`);
process.exit(1);
}
} else {
console.warn(`No secret data found at ${secretsPath} (see lib/server-secrets.js)`);
}

View File

@ -1,13 +1,6 @@
var nodeUrl = require('url'); var nodeUrl = require('url');
var request = require('request'); var request = require('request');
var serverSecrets; var serverSecrets = require('./server-secrets');
try {
// Everything that cannot be checked in but is useful server-side
// is stored in this JSON data.
serverSecrets = require('../private/secret.json');
} catch(e) {
console.error('No secret data (private/secret.json, see server.js):', e);
}
// data: {url}, JSON-serializable object. // data: {url}, JSON-serializable object.
// end: function(json), with json of the form: // end: function(json), with json of the form:

View File

@ -29,14 +29,7 @@ var loadLogos = require('./lib/load-logos.js');
var githubAuth = require('./lib/github-auth.js'); var githubAuth = require('./lib/github-auth.js');
var querystring = require('querystring'); var querystring = require('querystring');
var xml2js = require('xml2js'); var xml2js = require('xml2js');
var serverSecrets; var serverSecrets = require('./lib/server-secrets');
try {
// Everything that cannot be checked in but is useful server-side
// is stored in this JSON data.
serverSecrets = require('./private/secret.json');
} catch(e) {
console.error('No secret data (private/secret.json, see server.js):', e);
}
if (serverSecrets && serverSecrets.gh_client_id) { if (serverSecrets && serverSecrets.gh_client_id) {
githubAuth.setRoutes(camp); githubAuth.setRoutes(camp);
} }