Skip to content
This repository was archived by the owner on Sep 2, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ node_modules

*.local

config.*
config.env
config.json
3 changes: 2 additions & 1 deletion app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ if ( process.env.NEW_RELIC_ENABLED ) {
require( "newrelic" );
}

const config = require('./lib/config');
const restify = require('restify');
const applyRoutes = require('./routes');
const logger = require('./lib/logger')
Expand All @@ -32,7 +33,7 @@ applyRoutes(server);
module.exports = server;

if (!module.parent) {
server.listen(process.env.PORT || 8080, function () {
server.listen( config( 'PORT', 8080), function () {
console.log('%s listening at %s', server.name, server.url);
});
}
8 changes: 8 additions & 0 deletions app/lib/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const path = require('path');
const config = require('config-store');

try {
exports = module.exports = config(path.join(__dirname, '../../config.json'));
} catch (e) {
exports = module.exports = config();
}
9 changes: 5 additions & 4 deletions app/lib/db.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
var streamsql = require('streamsql');
var mysql = require('mysql');
const config = require('./config');

var options = {
driver: 'mysql',
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
host: config( 'DB_HOST'),
user: config( 'DB_USER'),
password: config( 'DB_PASSWORD'),
database: config( 'DB_NAME'),
}

var db = streamsql.connect(options);
Expand Down
6 changes: 4 additions & 2 deletions app/lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const restify = require('restify')
const url = require('url')
const log = require('../lib/logger')
const hash = require('../lib/hash').hash
const config = require('../lib/config');

const models = {
system: require('../models/system'),
issuer: require('../models/issuer'),
Expand Down Expand Up @@ -128,7 +130,7 @@ function attachPageData() {
}

function verifyRequest() {
if (process.env.NODE_ENV == 'test') {
if ( process.env.NODE_ENV == 'test') {
log.warn('In test environment, bypassing request verification')
return function (req, res, next) {
return next()
Expand Down Expand Up @@ -198,7 +200,7 @@ function verifyRequest() {
return next(new http403('Missing JWT claim: key'))

if (auth.key === 'master') {
const masterSecret = process.env.MASTER_SECRET
const masterSecret = config( 'MASTER_SECRET')
if (!jws.verify(token, masterSecret))
return next(new http403('Invalid token signature'))
return success()
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"async": "~0.2.10",
"db-migrate": "~0.6.3",
"optimist": "~0.6.1",
"lodash": "~2.4.1"
"lodash": "~2.4.1",
"config-store": "~0.2.0"
},
"devDependencies": {
"concat-stream": "~1.4.1",
Expand Down