ditch nestjs config module, add static config serfice

This commit is contained in:
Jurgis Sakalauskas
2022-12-09 11:37:44 +02:00
parent b353e00bec
commit 7e5fa1fb2a
11 changed files with 86 additions and 102 deletions
+40
View File
@@ -0,0 +1,40 @@
import * as env from 'dotenv';
import { TypeOrmModuleOptions } from '@nestjs/typeorm';
import { LrtCategory } from '../KodiApi/LRT/LrtApiClient/Entity/lrt-category.entity';
import { join } from 'path';
env.config();
class ConfigService {
public getEnv(key: string): any {
return process.env[key];
}
public getPort(): number {
const port = this.getEnv('PORT');
return port ? parseInt(port) : 3000;
}
public getTypeOrmConfig(): TypeOrmModuleOptions {
return {
type: 'sqlite',
database: this.getEnv('DB_PATH'),
entities: [LrtCategory],
};
}
public getStaticRequestsLogPath(): string {
return join(this.getRootPath(), this.getEnv('LOG_FILE_REQUESTS'));
}
public getStaticFolder(): string {
return join(this.getRootPath(), this.getEnv('STATIC_SERVE_FOLDER'));
}
private getRootPath(): string {
return join(__dirname, '../..');
}
}
export const configService = new ConfigService();