Skip to content

Commit

Permalink
feat: updates to default config
Browse files Browse the repository at this point in the history
  • Loading branch information
jrassa committed Feb 8, 2024
1 parent aae0adc commit b90634c
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 146 deletions.
59 changes: 27 additions & 32 deletions config/default.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
'use strict';

const contactEmail =
process.env.CONTACT_EMAIL ||
process.env.MAILER_ADMIN ||
'[email protected]';
const contactEmail = process.env.CONTACT_EMAIL || '[email protected]';

module.exports = {
mode: 'production',

// The port to use for the application (defaults to the environment variable if present)
port: process.env.PORT || 3001,
port: 3000,

// Basic title and instance name
app: {
Expand All @@ -18,7 +14,7 @@ module.exports = {
description: 'Node REST app',
clientUrl: 'http://localhost/#',
helpUrl: 'http://localhost/#/help',
contactEmail: contactEmail
contactEmail: '[email protected]'
},

/**
Expand All @@ -43,6 +39,17 @@ module.exports = {
socketio: {
ignoreOlderThan: 600
},
// Use the following for local eventEmitter
publishProvider: './src/app/common/event/event-publish.provider',
socketProvider: './src/app/common/sockets/event-socket.provider',

messages: {
topic: 'message.posted'
},

pages: {
topic: 'page.updated'
},

cors: {
enabled: false,
Expand Down Expand Up @@ -126,7 +133,7 @@ module.exports = {
autoLogin: false,
autoCreateAccounts: false,
defaultRoles: {},
// requiredRoles: ['ROLE'],
requiredRoles: [],

roles: ['user', 'editor', 'auditor', 'admin'],
roleStrategy: 'local', // 'local' || 'external' || 'hybrid'
Expand Down Expand Up @@ -210,21 +217,26 @@ module.exports = {
*/
maxCountTimeMS: 5000,

// configures mongo TTL index. Overriding these may require dropping existing index
notificationExpires: 15552000, // 180 days
auditExpires: 15552000, //180 days
feedbackExpires: 15552000, // 180 days

/**
* Environment Settings
*/

// Configuration for outgoing mail server / service
mailer: {
from: process.env.MAILER_FROM || '[email protected]',
from: '[email protected]',
provider: './src/app/core/email/providers/smtp-email.provider',
options: {
host: process.env.MAILER_SERVICE_PROVIDER || 'gmail',
host: 'gmail',
port: 587,
secure: false, // true for 465, false for other ports
auth: {
user: process.env.MAILER_EMAIL_ID || '[email protected]',
pass: process.env.MAILER_PASSWORD || 'PASSWORD'
user: '[email protected]',
pass: 'PASSWORD'
}
}
/*
Expand Down Expand Up @@ -321,23 +333,6 @@ module.exports = {

siteEmails: {},

// Use the following for local eventEmitter
publishProvider: './src/app/common/event/event-publish.provider',
socketProvider: './src/app/common/sockets/event-socket.provider',

messages: {
topic: 'message.posted'
},

pages: {
topic: 'page.updated'
},

// configures mongo TTL index. Overriding these may require dropping existing index
notificationExpires: 15552000, // 180 days
auditExpires: 15552000, //180 days
feedbackExpires: 15552000, // 180 days

teams: {
implicitMembers: {
/**
Expand Down Expand Up @@ -365,7 +360,7 @@ module.exports = {
*/

// Expose server errors to the client (500 errors)
exposeServerErrors: true,
exposeServerErrors: false,

// Mongoose query logging
mongooseLogging: false,
Expand All @@ -383,7 +378,7 @@ module.exports = {
// Console logger
{
stream: 'process.stdout',
level: 'info'
level: 'warn'
} //,
// Rotating file logger
//{
Expand Down Expand Up @@ -448,7 +443,7 @@ module.exports = {
// Copyright footer (shown above the system footer)
copyright: {
// HTML-enabled contents of the banner
html: 'Copyright © 2018 <a href="http://www.asymmetrik.com" target="_blank">Asymmetrik, Ltd</a>. All Rights Reserved.'
html: '© 2024 <a href="http://www.bluehalo.com" target="_blank">BLUEHALO</a>'
},

feedback: {
Expand Down
80 changes: 1 addition & 79 deletions config/production.js
Original file line number Diff line number Diff line change
@@ -1,81 +1,3 @@
'use strict';

module.exports = {

/**
* System Settings
*/


/**
* Environment Settings
*/


/**
* Development/debugging settings
*/

// Expose server errors to the client (500 errors)
exposeServerErrors: false,

// Mongoose query logging
mongooseLogging: false,

// Express route logging
expressLogging: false,


/**
* Logging Settings
*/

// Application logging and logstash
logger: {
application: [
// Console logger
{
stream: process.stdout,
level: 'warn'
},
// Rotating file logger
{
type: 'rotating-file',
level: 'warn',
path: '/var/log/mean2/application.log',
period: '1d',
count: 1
}
// Logstash logger
// {
// type: 'raw',
// level: 'info',
// stream: logstash.createStream({
// host: 'localhost',
// port: 4561
// })
// }
],
audit: [
// Console logger (audit logger must be 'info' level)
{
stream: process.stdout,
level: 'info'
},
// Rotating file logger
{
type: 'rotating-file',
level: 'info',
path: '/usr/local/var/log/mean2/audit.log',
period: '1d',
count: 7
}
]
}


/**
* Not So Environment-Specific Settings
*/

};
module.exports = {};
5 changes: 3 additions & 2 deletions src/app/common/express/error-handlers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import config from 'config';
import { ValidationError } from 'express-json-validator-middleware';
import _ from 'lodash';

import { config, logger } from '../../../dependencies';
import { logger } from '../../../dependencies';

const getStatus = (err) => {
logger.error(err.status < 400);
Expand Down Expand Up @@ -84,7 +85,7 @@ export const defaultErrorHandler = (err, req, res, next) => {

if (errorResponse.status >= 500 && errorResponse.status < 600) {
// Swap the error message if `exposeServerErrors` is disabled
if (!config.exposeServerErrors) {
if (!config.get<boolean>('exposeServerErrors')) {
errorResponse.message = 'A server error has occurred.';
delete errorResponse.stack;
}
Expand Down
7 changes: 3 additions & 4 deletions src/app/common/mongoose/paginate.plugin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import config from 'config';
import { HydratedDocument, Query, Schema } from 'mongoose';

import { config } from '../../../dependencies';

const MONGO_TIMEOUT_ERROR_CODE = 50;

export interface PagingResults<DocType> {
Expand All @@ -27,7 +26,7 @@ export function paginatePlugin(schema: Schema) {
pageSize: number,
pageNumber: number,
runCount = true,
countTimeout = config.maxCountTimeMS
countTimeout = config.get<number>('maxCountTimeMS')
): Promise<PagingResults<DocType>> {
const countPromise = runCount
? this.model
Expand All @@ -46,7 +45,7 @@ export function paginatePlugin(schema: Schema) {

const resultsPromise = this.skip(pageNumber * pageSize)
.limit(pageSize)
.maxTimeMS(config.maxTimeMS)
.maxTimeMS(config.get<number>('maxTimeMS'))
.exec();

const [totalSize, elements] = await Promise.all([
Expand Down
5 changes: 3 additions & 2 deletions src/app/common/sockets/base-socket.provider.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as async from 'async';
import config from 'config';
import { Request, RequestHandler, Response } from 'express';
import { Socket } from 'socket.io';

import { config, logger } from '../../../dependencies';
import { logger } from '../../../dependencies';

// If this is not null, ignore any messages that are older than this number of seconds.
const ignoreOlderThan = config.socketio.ignoreOlderThan;
const ignoreOlderThan = config.get<number>('socketio.ignoreOlderThan');

export type SocketConfig = {
emitName?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/app/common/util.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ describe('Utils:', () => {
let originalExposeServerErrors;

before(() => {
originalExposeServerErrors = config.exposeServerErrors;
originalExposeServerErrors = config.get<string>('exposeServerErrors');
});

after(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/app/common/util.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const getErrorMessage = function (err) {
* @deprecated
*/
export const getClientErrorMessage = function (err) {
if (config.exposeServerErrors) {
if (config.get<boolean>('exposeServerErrors')) {
return getErrorMessage(err);
} else {
return 'A server error has occurred.';
Expand Down
6 changes: 3 additions & 3 deletions src/app/core/audit/audit.model.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import config from 'config';
import { HydratedDocument, Model, model, Schema } from 'mongoose';

import { config } from '../../../dependencies';
import {
ContainsSearchable,
containsSearchPlugin
Expand Down Expand Up @@ -71,12 +71,12 @@ AuditSchema.plugin(containsSearchPlugin, {
*/

// created datetime index, expires after configured time (false to disable TTL)
if (config.auditExpires === false) {
if (config.get('auditExpires') === false) {
AuditSchema.index({ created: -1 });
} else {
AuditSchema.index(
{ created: -1 },
{ expireAfterSeconds: config.auditExpires ?? 15552000 }
{ expireAfterSeconds: config.get<number>('auditExpires') }
);
}

Expand Down
19 changes: 8 additions & 11 deletions src/app/core/audit/audit.service.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import config from 'config';
import { Request } from 'express';

import { Audit, AuditDocument } from './audit.model';
import {
config,
logger,
auditLogger,
utilService
} from '../../../dependencies';
import { logger, auditLogger, utilService } from '../../../dependencies';
import { IUser, UserDocument } from '../user/user.model';

class AuditService {
Expand Down Expand Up @@ -90,13 +86,14 @@ class AuditService {
* Creates an audit entry persisted to Mongo and the bunyan logger
*/
private getMasqueradingUserDn(eventActor, headers) {
if (config.auth.strategy === 'proxy-pki' && config.auth.masquerade) {
if (
config.get<string>('auth.strategy') === 'proxy-pki' &&
config.get<boolean>('auth.masquerade')
) {
const masqueradeUserDn =
headers?.[config.masqueradeUserHeader ?? 'x-masquerade-user-dn'];
headers?.[config.get<string>('masqueradeUserHeader')];
if (eventActor.dn && eventActor.dn === masqueradeUserDn) {
return headers?.[
config.proxyPkiPrimaryUserHeader ?? 'x-ssl-client-s-dn'
];
return headers?.[config.get<string>('proxyPkiPrimaryUserHeader')];
}
}
return undefined;
Expand Down
16 changes: 8 additions & 8 deletions src/lib/express.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ describe('Init Swagger API:', () => {
swaggerDefinition: {
openapi: '3.0.2',
info: {
title: config.app.title,
description: config.app.description,
title: config.get<string>('app.title'),
description: config.get<string>('app.description'),
version: 'test'
},
servers: [
Expand All @@ -28,19 +28,19 @@ describe('Init Swagger API:', () => {
components: {}
},
apis: [
...globSync(config.assets.docs).map((doc: string) =>
...globSync(config.get<string[]>('assets.docs')).map((doc: string) =>
path.posix.resolve(doc)
),
...globSync(config.assets.routes).map((route: string) =>
path.posix.resolve(route)
...globSync(config.get<string[]>('assets.routes')).map(
(route: string) => path.posix.resolve(route)
),
...globSync(config.assets.models).map((model: string) =>
path.posix.resolve(model)
...globSync(config.get<string[]>('assets.models')).map(
(model: string) => path.posix.resolve(model)
)
]
};

if (config.auth.strategy === 'local') {
if (config.get<string>('auth.strategy') === 'local') {
swaggerOptions.swaggerDefinition.components.securitySchemes = {
basicAuth: {
type: 'http',
Expand Down
Loading

0 comments on commit b90634c

Please sign in to comment.