summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Server.ts28
-rw-r--r--src/api/middlewares/TestClient.ts7
-rw-r--r--src/util/config/Config.ts10
-rw-r--r--src/util/config/types/EndpointConfiguration.ts1
-rw-r--r--src/util/util/Config.ts13
5 files changed, 22 insertions, 37 deletions
diff --git a/src/Server.ts b/src/Server.ts

index c94c3bc7..83e16fa6 100644 --- a/src/Server.ts +++ b/src/Server.ts
@@ -38,34 +38,6 @@ async function main() { server.listen(port); await getOrInitialiseDatabase(); await Config.init(); - // only set endpointPublic, if not already set - await Config.set({ - cdn: { - endpointClient: "${location.host}", - endpointPrivate: `http://localhost:${port}` - }, - gateway: { - endpointClient: '${location.protocol === "https:" ? "wss://" : "ws://"}${location.host}', - endpointPrivate: `ws://localhost:${port}`, - ...(!Config.get().gateway.endpointPublic && { - endpointPublic: `ws://localhost:${port}` - }) - } - // regions: { - // default: "fosscord", - // useDefaultAsOptimal: true, - // available: [ - // { - // id: "fosscord", - // name: "Fosscord", - // endpoint: "127.0.0.1:3001", - // vip: false, - // custom: false, - // deprecated: false, - // }, - // ], - // }, - } as any); //Sentry if (Config.get().sentry.enabled) { diff --git a/src/api/middlewares/TestClient.ts b/src/api/middlewares/TestClient.ts
index 2c872068..2784c8ab 100644 --- a/src/api/middlewares/TestClient.ts +++ b/src/api/middlewares/TestClient.ts
@@ -94,11 +94,8 @@ export default function TestClient(app: Application) { } function applyEnv(html: string): string { - const CDN_ENDPOINT = (Config.get().cdn.endpointClient || Config.get()?.cdn.endpointPublic || process.env.CDN || "").replace( - /(https?)?(:\/\/?)/g, - "" - ); - const GATEWAY_ENDPOINT = Config.get().gateway.endpointClient || Config.get()?.gateway.endpointPublic || process.env.GATEWAY || ""; + const CDN_ENDPOINT = (Config.get()?.cdn.endpointPublic || process.env.CDN || "").replace(/(https?)?(:\/\/?)/g, ""); + const GATEWAY_ENDPOINT = Config.get()?.gateway.endpointPublic || process.env.GATEWAY || ""; if (CDN_ENDPOINT) { html = html.replace(/CDN_HOST: .+/, `CDN_HOST: \`${CDN_ENDPOINT}\`,`); diff --git a/src/util/config/Config.ts b/src/util/config/Config.ts
index 27450f95..36c4509d 100644 --- a/src/util/config/Config.ts +++ b/src/util/config/Config.ts
@@ -19,8 +19,14 @@ import { } from "."; export class ConfigValue { - gateway: EndpointConfiguration = new EndpointConfiguration(); - cdn: EndpointConfiguration = new EndpointConfiguration(); + gateway: EndpointConfiguration = { + endpointPublic: '${location.protocol === "https:" ? "wss://" : "ws://"}${location.host}', + endpointPrivate: `ws://localhost:3001` + }; + cdn: EndpointConfiguration = { + endpointPublic: "${location.host}", + endpointPrivate: `http://localhost:3001` + }; api: ApiConfiguration = new ApiConfiguration(); general: GeneralConfiguration = new GeneralConfiguration(); limits: LimitsConfiguration = new LimitsConfiguration(); diff --git a/src/util/config/types/EndpointConfiguration.ts b/src/util/config/types/EndpointConfiguration.ts
index 5e5e8ca9..26f3106f 100644 --- a/src/util/config/types/EndpointConfiguration.ts +++ b/src/util/config/types/EndpointConfiguration.ts
@@ -1,5 +1,4 @@ export class EndpointConfiguration { - endpointClient: string | null = null; endpointPrivate: string | null = null; endpointPublic: string | null = null; } diff --git a/src/util/util/Config.ts b/src/util/util/Config.ts
index 6d43b24c..cc7090a6 100644 --- a/src/util/util/Config.ts +++ b/src/util/util/Config.ts
@@ -1,4 +1,5 @@ import fs from "fs"; +import path from "path"; import { OrmUtils } from "."; import { ConfigValue } from "../config"; import { ConfigEntity } from "../entities/Config"; @@ -24,11 +25,21 @@ export const Config = { if (process.env.CONFIG_PATH) try { const overrideConfig = JSON.parse(fs.readFileSync(overridePath, { encoding: "utf8" })); - config = overrideConfig.merge(config); + config = OrmUtils.mergeDeep(config, overrideConfig); } catch (error) { fs.writeFileSync(overridePath, JSON.stringify(config, null, 4)); } + if (fs.existsSync(path.join(process.cwd(), "initial.json"))) + try { + console.log("[Config] Found initial configuration, merging..."); + const overrideConfig = JSON.parse(fs.readFileSync(path.join(process.cwd(), "initial.json"), { encoding: "utf8" })); + config = OrmUtils.mergeDeep(config, overrideConfig); + fs.rmSync(path.join(process.cwd(), "initial.json")); + } catch (error) { + fs.writeFileSync(path.join(process.cwd(), "failed.conf"), JSON.stringify(config, null, 4)); + } + return this.set(config); }, get: function get() {