fix: set config file before accessing it

Closes #27
This commit is contained in:
Jovan Krunić
2019-03-11 15:45:32 +01:00
committed by Rainer Killinger
parent d110d60123
commit e17db521e2
4 changed files with 11 additions and 13 deletions

View File

@@ -14,7 +14,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {
SCConfigFile,
SCNotFoundErrorResponse,
SCRequestBodyTooLargeErrorResponse,
SCSyntaxErrorResponse,
@@ -26,7 +25,7 @@ import * as cors from 'cors';
import * as express from 'express';
import * as morgan from 'morgan';
import {join} from 'path';
import {logger, mailer} from './common';
import {configFile, logger, mailer} from './common';
import {MailQueue} from './notification/MailQueue';
import {bulkAddRouter} from './routes/BulkAddRoute';
import {bulkDoneRouter} from './routes/BulkDoneRoute';
@@ -41,7 +40,6 @@ import {Elasticsearch} from './storage/elasticsearch/Elasticsearch';
export const app = express();
const isTestEnvironment = process.env.NODE_ENV !== 'production';
const configFile: SCConfigFile = app.get('config');
async function configureApp() {
// request loggers have to be the first middleware to be set in express
@@ -113,9 +111,7 @@ async function configureApp() {
await scValidator.addSchemas(join('node_modules', '@openstapps', 'core', 'lib', 'schema'));
// validate the config file
const configValidation = scValidator.validate(config.util.toObject(), 'SCConfigFile');
// use the config file
app.set('config', config.util.toObject());
const configValidation = scValidator.validate(configFile, 'SCConfigFile');
// validation failed
if (configValidation.errors.length > 0) {
@@ -139,7 +135,7 @@ async function configureApp() {
const database =
new databases[config.get<string>('internal.database.name')](
config.util.toObject(),
configFile,
app.get('mailQueue'),
);