mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 09:03:02 +00:00
committed by
Rainer Killinger
parent
d110d60123
commit
e17db521e2
10
src/app.ts
10
src/app.ts
@@ -14,7 +14,6 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
import {
|
import {
|
||||||
SCConfigFile,
|
|
||||||
SCNotFoundErrorResponse,
|
SCNotFoundErrorResponse,
|
||||||
SCRequestBodyTooLargeErrorResponse,
|
SCRequestBodyTooLargeErrorResponse,
|
||||||
SCSyntaxErrorResponse,
|
SCSyntaxErrorResponse,
|
||||||
@@ -26,7 +25,7 @@ import * as cors from 'cors';
|
|||||||
import * as express from 'express';
|
import * as express from 'express';
|
||||||
import * as morgan from 'morgan';
|
import * as morgan from 'morgan';
|
||||||
import {join} from 'path';
|
import {join} from 'path';
|
||||||
import {logger, mailer} from './common';
|
import {configFile, logger, mailer} from './common';
|
||||||
import {MailQueue} from './notification/MailQueue';
|
import {MailQueue} from './notification/MailQueue';
|
||||||
import {bulkAddRouter} from './routes/BulkAddRoute';
|
import {bulkAddRouter} from './routes/BulkAddRoute';
|
||||||
import {bulkDoneRouter} from './routes/BulkDoneRoute';
|
import {bulkDoneRouter} from './routes/BulkDoneRoute';
|
||||||
@@ -41,7 +40,6 @@ import {Elasticsearch} from './storage/elasticsearch/Elasticsearch';
|
|||||||
|
|
||||||
export const app = express();
|
export const app = express();
|
||||||
const isTestEnvironment = process.env.NODE_ENV !== 'production';
|
const isTestEnvironment = process.env.NODE_ENV !== 'production';
|
||||||
const configFile: SCConfigFile = app.get('config');
|
|
||||||
|
|
||||||
async function configureApp() {
|
async function configureApp() {
|
||||||
// request loggers have to be the first middleware to be set in express
|
// 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'));
|
await scValidator.addSchemas(join('node_modules', '@openstapps', 'core', 'lib', 'schema'));
|
||||||
|
|
||||||
// validate the config file
|
// validate the config file
|
||||||
const configValidation = scValidator.validate(config.util.toObject(), 'SCConfigFile');
|
const configValidation = scValidator.validate(configFile, 'SCConfigFile');
|
||||||
// use the config file
|
|
||||||
app.set('config', config.util.toObject());
|
|
||||||
|
|
||||||
// validation failed
|
// validation failed
|
||||||
if (configValidation.errors.length > 0) {
|
if (configValidation.errors.length > 0) {
|
||||||
@@ -139,7 +135,7 @@ async function configureApp() {
|
|||||||
|
|
||||||
const database =
|
const database =
|
||||||
new databases[config.get<string>('internal.database.name')](
|
new databases[config.get<string>('internal.database.name')](
|
||||||
config.util.toObject(),
|
configFile,
|
||||||
app.get('mailQueue'),
|
app.get('mailQueue'),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -13,9 +13,13 @@
|
|||||||
* You should have received a copy of the GNU Affero General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
import {SCConfigFile} from '@openstapps/core';
|
||||||
import {Logger} from '@openstapps/logger';
|
import {Logger} from '@openstapps/logger';
|
||||||
|
import * as config from 'config';
|
||||||
import {BackendTransport} from './notification/BackendTransport';
|
import {BackendTransport} from './notification/BackendTransport';
|
||||||
|
|
||||||
export const mailer = BackendTransport.getTransportInstance();
|
export const mailer = BackendTransport.getTransportInstance();
|
||||||
|
|
||||||
export const logger = new Logger(mailer);
|
export const logger = new Logger(mailer);
|
||||||
|
|
||||||
|
export const configFile: SCConfigFile = config.util.toObject();
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
import {SCConfigFile, SCIndexResponse, SCIndexRoute} from '@openstapps/core';
|
import {SCConfigFile, SCIndexResponse, SCIndexRoute} from '@openstapps/core';
|
||||||
import * as config from 'config';
|
import {configFile} from '../common';
|
||||||
import {createRoute} from './Route';
|
import {createRoute} from './Route';
|
||||||
|
|
||||||
const indexRouteModel = new SCIndexRoute();
|
const indexRouteModel = new SCIndexRoute();
|
||||||
@@ -25,8 +25,7 @@ const indexRouteModel = new SCIndexRoute();
|
|||||||
export const indexRouter = createRoute<SCIndexResponse>(
|
export const indexRouter = createRoute<SCIndexResponse>(
|
||||||
indexRouteModel,
|
indexRouteModel,
|
||||||
async (_request: SCIndexRoute, _app) => {
|
async (_request: SCIndexRoute, _app) => {
|
||||||
const configObject: SCConfigFile = config.util.toObject();
|
const {internal, ...configObject}: SCConfigFile = configFile;
|
||||||
delete configObject.internal;
|
|
||||||
return configObject;
|
return configObject;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -14,13 +14,13 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
import {
|
import {
|
||||||
SCConfigFile,
|
|
||||||
SCMultiSearchRequest,
|
SCMultiSearchRequest,
|
||||||
SCMultiSearchResponse,
|
SCMultiSearchResponse,
|
||||||
SCMultiSearchRoute,
|
SCMultiSearchRoute,
|
||||||
SCSearchResponse,
|
SCSearchResponse,
|
||||||
SCTooManyRequestsErrorResponse,
|
SCTooManyRequestsErrorResponse,
|
||||||
} from '@openstapps/core';
|
} from '@openstapps/core';
|
||||||
|
import {configFile} from '../common';
|
||||||
import {BulkStorage} from '../storage/BulkStorage';
|
import {BulkStorage} from '../storage/BulkStorage';
|
||||||
import {createRoute} from './Route';
|
import {createRoute} from './Route';
|
||||||
|
|
||||||
@@ -33,11 +33,10 @@ export const multiSearchRouter = createRoute<SCMultiSearchResponse | SCTooManyRe
|
|||||||
multiSearchRouteModel,
|
multiSearchRouteModel,
|
||||||
async (request: SCMultiSearchRequest, app) => {
|
async (request: SCMultiSearchRequest, app) => {
|
||||||
|
|
||||||
const config: SCConfigFile = app.get('config');
|
|
||||||
const bulkMemory: BulkStorage = app.get('bulk');
|
const bulkMemory: BulkStorage = app.get('bulk');
|
||||||
const queryNames = Object.keys(request);
|
const queryNames = Object.keys(request);
|
||||||
|
|
||||||
if (queryNames.length > config.backend.maxMultiSearchRouteQueries) {
|
if (queryNames.length > configFile.backend.maxMultiSearchRouteQueries) {
|
||||||
throw new SCTooManyRequestsErrorResponse(app.get('isProductiveEnvironment'));
|
throw new SCTooManyRequestsErrorResponse(app.get('isProductiveEnvironment'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user