54 lines
1.5 KiB
TypeScript
54 lines
1.5 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.name);
|
|
|
|
constructor(private readonly configService: ConfigService) {
|
|
this.logger.log('Production: ' + this.isProduction());
|
|
this.logger.log('Verbose: ' + this.isVerbose());
|
|
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 isVerbose() {
|
|
return ParseBool(this.configService.get(`${EnvPrefix}VERBOSE`), false);
|
|
}
|
|
|
|
public getVersion() {
|
|
return ParseString(this.configService.get(`npm_package_version`), '0.0.0');
|
|
}
|
|
}
|