getConfig()

This commit is contained in:
DarkCat09 2023-09-21 16:28:55 +04:00
parent 553efb1da6
commit f56b79c563
No known key found for this signature in database
GPG Key ID: 0A26CD5B3345D6E3
2 changed files with 18 additions and 9 deletions

View File

@ -17,18 +17,15 @@ import rawHtml from "./routes/api/raw-html";
import publicConfig from "./publicConfig";
import errorHandler from "./errors/handler";
import getConfig from "./config/main";
class App {
config: ConfigService;
constructor() {
this.config = new ConfigService();
}
async init() {
const config = getConfig();
const fastify = Fastify({
logger: true,
trustProxy: this.config.reverse_proxy,
trustProxy: config.reverse_proxy,
});
fastify.register(fastifyStatic, {
@ -56,7 +53,7 @@ class App {
fastify.register(indexRoute);
fastify.register(getRoute);
if (this.config.proxy_res)
if (config.proxy_res)
fastify.register(proxyRoute);
fastify.register(parseRoute);
@ -65,7 +62,7 @@ class App {
fastify.setErrorHandler(errorHandler);
fastify.listen(
{ host: this.config.host, port: this.config.port },
{ host: config.host, port: config.port },
(err) => {
err && console.log(err);
}

12
src/config/main.ts Normal file
View File

@ -0,0 +1,12 @@
import { ConfigService } from "./config.service";
let configSvc: ConfigService | undefined;
export default function getConfig(): ConfigService {
if (configSvc) {
return configSvc;
}
configSvc = new ConfigService();
return configSvc;
}