diff --git a/src/app.ts b/src/app.ts
index ef93ea80..007172b1 100644
--- a/src/app.ts
+++ b/src/app.ts
@@ -14,7 +14,6 @@
* along with this program. If not, see .
*/
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('internal.database.name')](
- config.util.toObject(),
+ configFile,
app.get('mailQueue'),
);
diff --git a/src/common.ts b/src/common.ts
index b6189d74..73d265f6 100644
--- a/src/common.ts
+++ b/src/common.ts
@@ -13,9 +13,13 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
+import {SCConfigFile} from '@openstapps/core';
import {Logger} from '@openstapps/logger';
+import * as config from 'config';
import {BackendTransport} from './notification/BackendTransport';
export const mailer = BackendTransport.getTransportInstance();
export const logger = new Logger(mailer);
+
+export const configFile: SCConfigFile = config.util.toObject();
diff --git a/src/routes/IndexRoute.ts b/src/routes/IndexRoute.ts
index 6292acff..85a88dd5 100644
--- a/src/routes/IndexRoute.ts
+++ b/src/routes/IndexRoute.ts
@@ -14,7 +14,7 @@
* along with this program. If not, see .
*/
import {SCConfigFile, SCIndexResponse, SCIndexRoute} from '@openstapps/core';
-import * as config from 'config';
+import {configFile} from '../common';
import {createRoute} from './Route';
const indexRouteModel = new SCIndexRoute();
@@ -25,8 +25,7 @@ const indexRouteModel = new SCIndexRoute();
export const indexRouter = createRoute(
indexRouteModel,
async (_request: SCIndexRoute, _app) => {
- const configObject: SCConfigFile = config.util.toObject();
- delete configObject.internal;
+ const {internal, ...configObject}: SCConfigFile = configFile;
return configObject;
},
);
diff --git a/src/routes/MultiSearchRoute.ts b/src/routes/MultiSearchRoute.ts
index 01f18b32..a3e9a933 100644
--- a/src/routes/MultiSearchRoute.ts
+++ b/src/routes/MultiSearchRoute.ts
@@ -14,13 +14,13 @@
* along with this program. If not, see .
*/
import {
- SCConfigFile,
SCMultiSearchRequest,
SCMultiSearchResponse,
SCMultiSearchRoute,
SCSearchResponse,
SCTooManyRequestsErrorResponse,
} from '@openstapps/core';
+import {configFile} from '../common';
import {BulkStorage} from '../storage/BulkStorage';
import {createRoute} from './Route';
@@ -33,11 +33,10 @@ export const multiSearchRouter = createRoute {
- const config: SCConfigFile = app.get('config');
const bulkMemory: BulkStorage = app.get('bulk');
const queryNames = Object.keys(request);
- if (queryNames.length > config.backend.maxMultiSearchRouteQueries) {
+ if (queryNames.length > configFile.backend.maxMultiSearchRouteQueries) {
throw new SCTooManyRequestsErrorResponse(app.get('isProductiveEnvironment'));
}