Picsur/backend/src/config/early/host.config.service.ts

49 lines
1.3 KiB
TypeScript

import { Injectable, Logger } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import {
ParseBool,
ParseInt,
ParseString
} from 'picsur-shared/dist/util/parse-simple';
import { EnvPrefix } from '../config.static';
@Injectable()
export class HostConfigService {
private readonly logger = new Logger('HostConfigService');
constructor(private readonly configService: ConfigService) {
this.logger.log('Production: ' + this.isProduction());
this.logger.log('Host: ' + this.getHost());
this.logger.log('Port: ' + this.getPort());
this.logger.log('Demo: ' + this.isDemo());
this.logger.log('Demo Interval: ' + this.getDemoInterval() / 1000 + 's');
}
public getHost(): string {
return ParseString(this.configService.get(`${EnvPrefix}HOST`), '0.0.0.0');
}
public getPort(): number {
return ParseInt(this.configService.get(`${EnvPrefix}PORT`), 8080);
}
public isDemo() {
return ParseBool(this.configService.get(`${EnvPrefix}DEMO`), false);
}
public getDemoInterval() {
return ParseInt(
this.configService.get(`${EnvPrefix}DEMO_INTERVAL`),
1000 * 60 * 5,
);
}
public isProduction() {
return ParseBool(this.configService.get(`${EnvPrefix}PRODUCTION`), false);
}
public getVersion() {
return ParseString(this.configService.get(`npm_package_version`), '0.0.0');
}
}