mirror of
https://github.com/sakaljurgis/kodi-api-server.git
synced 2026-07-09 04:47:41 +00:00
ditch nestjs config module, add static config serfice
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
import * as Dotenv from 'dotenv';
|
||||
const dotenv: any = Dotenv.config().parsed;
|
||||
|
||||
class Config {
|
||||
public readonly port = dotenv.PORT;
|
||||
getPort() {
|
||||
return process.env.PORT;
|
||||
}
|
||||
//todo - check dotenv again if not loaded before emmiting err.
|
||||
//works globally, loaded once
|
||||
}
|
||||
|
||||
export default new Config();
|
||||
@@ -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();
|
||||
Reference in New Issue
Block a user