diff --git a/.env.example b/.env.example index 2dfe009..22b7787 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,4 @@ -HOST=127.0.0.1 # set 0.0.0.0 if you don't use reverse proxy +HOST=127.0.0.1 # 0.0.0.0 if txtdot is not behind reverse proxy PORT=8080 -REVERSE_PROXY_ENABLED=true # if you use reverse proxy set x-forwarded-host \ No newline at end of file + +REVERSE_PROXY=true # only for reverse proxy; see docs diff --git a/src/app.ts b/src/app.ts index 84f06d7..266cdc5 100644 --- a/src/app.ts +++ b/src/app.ts @@ -27,7 +27,7 @@ class App { async init() { const fastify = Fastify({ logger: true, - trustProxy: this.config.reverse_proxy_enabled, + trustProxy: this.config.reverse_proxy, }); fastify.register(fastifyStatic, { diff --git a/src/config/config.service.ts b/src/config/config.service.ts index 10b8bfc..652404b 100644 --- a/src/config/config.service.ts +++ b/src/config/config.service.ts @@ -3,18 +3,14 @@ import { config } from "dotenv"; export class ConfigService { public readonly host: string; public readonly port: number; - public readonly reverse_proxy_enabled: boolean; + public readonly reverse_proxy: boolean; constructor() { - const parsed = config().parsed; - - if (!parsed) { - throw new Error("Invalid .env file"); - } + config(); this.host = process.env.HOST || "localhost"; this.port = Number(process.env.PORT) || 8080; - this.reverse_proxy_enabled = - Boolean(process.env.REVERSE_PROXY_ENABLED) || false; + + this.reverse_proxy = Boolean(process.env.REVERSE_PROXY) || false; } }