mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-19 16:13:06 +00:00
refactor: parameterize configureApp function (inject db list)
Reason: easier testing (mocking) and better readability Note: did additional refactoring
This commit is contained in:
committed by
Rainer Killinger
parent
f3b86f0f0d
commit
fe7dd09d7e
12
src/app.ts
12
src/app.ts
@@ -38,12 +38,11 @@ import {thingUpdateRouter} from './routes/thing-update-route';
|
||||
import {virtualPluginRoute} from './routes/virtual-plugin-route';
|
||||
import {BulkStorage} from './storage/bulk-storage';
|
||||
import {DatabaseConstructor} from './storage/database';
|
||||
import {Elasticsearch} from './storage/elasticsearch/elasticsearch';
|
||||
|
||||
/**
|
||||
* Configure the backend
|
||||
*/
|
||||
export async function configureApp(app: Express) {
|
||||
export async function configureApp(app: Express, databases: {[name: string]: DatabaseConstructor; }) {
|
||||
let integrationTestTimeout: NodeJS.Timeout;
|
||||
// request loggers have to be the first middleware to be set in express
|
||||
app.use(morgan('dev', {
|
||||
@@ -59,11 +58,8 @@ export async function configureApp(app: Express) {
|
||||
}
|
||||
|
||||
// tslint:disable-next-line: no-magic-numbers
|
||||
if (res.statusCode < 400) {
|
||||
return true;
|
||||
}
|
||||
return res.statusCode < 400;
|
||||
|
||||
return false;
|
||||
}, stream: process.stdout,
|
||||
}));
|
||||
|
||||
@@ -142,10 +138,6 @@ export async function configureApp(app: Express) {
|
||||
.on('end', endCallback);
|
||||
});
|
||||
|
||||
const databases: {[name: string]: DatabaseConstructor; } = {
|
||||
elasticsearch: Elasticsearch,
|
||||
};
|
||||
|
||||
// validate config file
|
||||
await validator.addSchemas(join('node_modules', '@openstapps', 'core', 'lib', 'schema'));
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import {Logger} from '@openstapps/logger';
|
||||
import express from 'express';
|
||||
import http from 'http';
|
||||
import {configureApp} from './app';
|
||||
import {Elasticsearch} from './storage/elasticsearch/elasticsearch';
|
||||
|
||||
const app = express();
|
||||
|
||||
@@ -95,7 +96,7 @@ function onListening() {
|
||||
Logger.ok(`Listening on ${bind}`);
|
||||
}
|
||||
|
||||
configureApp(app)
|
||||
configureApp(app, {elasticsearch: Elasticsearch})
|
||||
.then(() => {
|
||||
Logger.ok('Successfully configured express server');
|
||||
// After app setup listen on provided port, on all network interfaces
|
||||
|
||||
Reference in New Issue
Block a user