Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions redisinsight/api/config/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ export default {
},
server: {
version,
env: 'development',
env: process.env.NODE_ENV || 'development',
host: process.env.RI_APP_HOST ?? '0.0.0.0',
port: parseInt(process.env.RI_APP_PORT, 10) ?? 5000,
port: parseInt(process.env.RI_APP_PORT, 10) || 5000,
docPrefix: 'api/docs',
globalPrefix: 'api',
customPluginsUri: '/plugins',
Expand Down
3 changes: 3 additions & 0 deletions redisinsight/api/config/development.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export default {
server: {
env: 'development',
},
sockets: {
cors: true,
},
Expand Down
2 changes: 1 addition & 1 deletion redisinsight/api/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fs from 'fs';
import {
MiddlewareConsumer, Module, NestModule, OnModuleInit
MiddlewareConsumer, Module, NestModule, OnModuleInit,
} from '@nestjs/common';
import { ServeStaticModule } from '@nestjs/serve-static';
import { RouterModule } from 'nest-router';
Expand Down
2 changes: 1 addition & 1 deletion redisinsight/api/src/modules/server/server.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
mockServerRepository,
MockType,
} from 'src/__mocks__';
import config from 'src/utils/config';
import config, { Config } from 'src/utils/config';
import {
ServerInfoNotFoundException,
AppAnalyticsEvents,
Expand Down
43 changes: 43 additions & 0 deletions redisinsight/api/src/utils/config.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { Config } from 'src/utils/config';
import { merge } from 'lodash';
import defaultConfig from '../../config/default';
import devConfig from '../../config/development';
import testConfig from '../../config/test';
import stageConfig from '../../config/staging';
import prodConfig from '../../config/production';
import stackConfig from '../../config/stack';

describe('Config util', () => {
const OLD_ENV = process.env;
Expand Down Expand Up @@ -32,6 +36,35 @@ describe('Config util', () => {
});
});

it('should return test server config', () => {
process.env.NODE_ENV = 'test';
// eslint-disable-next-line global-require
const { get } = require('./config');

const result = get('server') as Config['server'];

expect(result).toEqual({
...defaultConfig.server,
...testConfig.server,
});
});

it('should return stack server config', () => {
process.env.BUILD_TYPE = 'REDIS_STACK';
process.env.NODE_ENV = 'staging';
// eslint-disable-next-line global-require
const { get } = require('./config');

const result = get('server') as Config['server'];

expect(result).toEqual({
...defaultConfig.server,
...stageConfig.server,
...stackConfig.server,
buildType: 'REDIS_STACK',
});
});

it('should return stage server config', () => {
process.env.NODE_ENV = 'staging';
// eslint-disable-next-line global-require
Expand All @@ -57,5 +90,15 @@ describe('Config util', () => {
...prodConfig.server,
});
});

it('should return entire prod server config', () => {
process.env.NODE_ENV = 'production';
// eslint-disable-next-line global-require
const { get } = require('./config');

const result = get() as Config['server'];

expect(result).toEqual(merge({ ...defaultConfig }, { ...prodConfig }));
});
});
});