getConfig()
This commit is contained in:
parent
553efb1da6
commit
f56b79c563
15
src/app.ts
15
src/app.ts
@ -17,18 +17,15 @@ import rawHtml from "./routes/api/raw-html";
|
|||||||
|
|
||||||
import publicConfig from "./publicConfig";
|
import publicConfig from "./publicConfig";
|
||||||
import errorHandler from "./errors/handler";
|
import errorHandler from "./errors/handler";
|
||||||
|
import getConfig from "./config/main";
|
||||||
|
|
||||||
class App {
|
class App {
|
||||||
config: ConfigService;
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
this.config = new ConfigService();
|
|
||||||
}
|
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
|
const config = getConfig();
|
||||||
|
|
||||||
const fastify = Fastify({
|
const fastify = Fastify({
|
||||||
logger: true,
|
logger: true,
|
||||||
trustProxy: this.config.reverse_proxy,
|
trustProxy: config.reverse_proxy,
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.register(fastifyStatic, {
|
fastify.register(fastifyStatic, {
|
||||||
@ -56,7 +53,7 @@ class App {
|
|||||||
fastify.register(indexRoute);
|
fastify.register(indexRoute);
|
||||||
fastify.register(getRoute);
|
fastify.register(getRoute);
|
||||||
|
|
||||||
if (this.config.proxy_res)
|
if (config.proxy_res)
|
||||||
fastify.register(proxyRoute);
|
fastify.register(proxyRoute);
|
||||||
|
|
||||||
fastify.register(parseRoute);
|
fastify.register(parseRoute);
|
||||||
@ -65,7 +62,7 @@ class App {
|
|||||||
fastify.setErrorHandler(errorHandler);
|
fastify.setErrorHandler(errorHandler);
|
||||||
|
|
||||||
fastify.listen(
|
fastify.listen(
|
||||||
{ host: this.config.host, port: this.config.port },
|
{ host: config.host, port: config.port },
|
||||||
(err) => {
|
(err) => {
|
||||||
err && console.log(err);
|
err && console.log(err);
|
||||||
}
|
}
|
||||||
|
12
src/config/main.ts
Normal file
12
src/config/main.ts
Normal 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;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user