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
2 changes: 1 addition & 1 deletion redisinsight/api/config/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const homedir = join(__dirname, '..');
const buildInfoFileName = 'build.json';
const dataZipFileName = 'data.zip';


const staticDir = process.env.BUILD_TYPE === 'ELECTRON' && process['resourcesPath']
? join(process['resourcesPath'], 'static')
: join(__dirname, '..', 'static');
Expand All @@ -17,6 +16,7 @@ const defaultsDir = process.env.BUILD_TYPE === 'ELECTRON' && process['resourcesP
export default {
dir_path: {
homedir,
prevHomedir: homedir,
staticDir,
defaultsDir,
logs: join(homedir, 'logs'),
Expand Down
5 changes: 4 additions & 1 deletion redisinsight/api/config/production.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import { join } from 'path';
import * as os from 'os';

const homedir = process.env.APP_FOLDER_ABSOLUTE_PATH
|| (join(os.homedir(), process.env.APP_FOLDER_NAME || '.redisinsight-preview'));
|| (join(os.homedir(), process.env.APP_FOLDER_NAME || '.redisinsight-v2'));

const prevHomedir = join(os.homedir(), '.redisinsight-preview');

export default {
dir_path: {
homedir,
prevHomedir,
logs: join(homedir, 'logs'),
customPlugins: join(homedir, 'plugins'),
commands: join(homedir, 'commands'),
Expand Down
5 changes: 4 additions & 1 deletion redisinsight/api/config/staging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import { join } from 'path';
import * as os from 'os';

const homedir = process.env.APP_FOLDER_ABSOLUTE_PATH
|| (join(os.homedir(), process.env.APP_FOLDER_NAME || '.redisinsight-v2.0-stage'));
|| (join(os.homedir(), process.env.APP_FOLDER_NAME || '.redisinsight-v2-stage'));

const prevHomedir = join(os.homedir(), '.redisinsight-v2.0-stage');

export default {
dir_path: {
homedir,
prevHomedir,
logs: join(homedir, 'logs'),
customPlugins: join(homedir, 'plugins'),
commands: join(homedir, 'commands'),
Expand Down
2 changes: 1 addition & 1 deletion redisinsight/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "redisinsight-api",
"version": "2.0.0",
"version": "2.0.5",
"description": "RedisInsight API",
"private": true,
"author": {
Expand Down
38 changes: 38 additions & 0 deletions redisinsight/api/src/init-helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import * as fs from 'fs-extra';
import config from 'src/utils/config';
import { join } from 'path';

const PATH_CONFIG = config.get('dir_path');
const DB_CONFIG = config.get('db');

/**
* Copy source if exists
* @param source
* @param destination
*/
const copySource = async (source, destination) => {
if (await fs.pathExists(source)) {
await fs.copy(source, destination).catch();
}
};

/**
* Migrate data from previous home folder defined in configs
*/
export const migrateHomeFolder = async () => {
try {
if (!(await fs.pathExists(DB_CONFIG.database)) && await fs.pathExists(PATH_CONFIG.prevHomedir)) {
await fs.ensureDir(PATH_CONFIG.homedir);

await Promise.all([
'redisinsight.db',
'plugins',
].map((target) => copySource(
join(PATH_CONFIG.prevHomedir, target),
join(PATH_CONFIG.homedir, target),
)));
}
} catch (e) {
// continue initialization even without migration
}
};
9 changes: 6 additions & 3 deletions redisinsight/api/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import 'dotenv/config'
import 'dotenv/config';
import { NestFactory } from '@nestjs/core';
import { SwaggerModule } from '@nestjs/swagger';
import { NestApplicationOptions } from '@nestjs/common';
import * as bodyParser from 'body-parser';
import { WinstonModule } from 'nest-winston';
import { GlobalExceptionFilter } from 'src/exceptions/global-exception.filter';
import { get } from 'src/utils';
import { migrateHomeFolder } from 'src/init-helper';
import { AppModule } from './app.module';
import SWAGGER_CONFIG from '../config/swagger';
import LOGGER_CONFIG from '../config/logger';
import config from './utils/config';

export default async function bootstrap() {
const serverConfig = config.get('server');
await migrateHomeFolder();

const serverConfig = get('server');
const port = process.env.API_PORT || serverConfig.port;
const logger = WinstonModule.createLogger(LOGGER_CONFIG);

Expand Down
1 change: 0 additions & 1 deletion redisinsight/api/test/test-runs/docker.build.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
APP_DATA_HOMEDIR=/root/.redisinsight-v2.0
COV_FOLDER=./coverage
ID=defaultid
RTE=defaultrte
Expand Down
1 change: 0 additions & 1 deletion redisinsight/api/test/test-runs/local.build.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
APP_DATA_HOMEDIR=/root/.redisinsight-2.0
COV_FOLDER=./coverage
ID=defaultid
RTE=defaultrte