diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-08-13 22:57:46 +0200 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-08-13 22:57:46 +0200 |
commit | 1f167e11df2535819a9d595f5302438fa52625b5 (patch) | |
tree | ffe704051842826603cabd7051e376a2f12aeb15 /api/src/middlewares | |
parent | Merge branch 'master' of https://github.com/fosscord/fosscord-api (diff) | |
download | server-1f167e11df2535819a9d595f5302438fa52625b5.tar.xz |
:construction: fix server bundle
Diffstat (limited to 'api/src/middlewares')
-rw-r--r-- | api/src/middlewares/TestClient.ts | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/api/src/middlewares/TestClient.ts b/api/src/middlewares/TestClient.ts index f93d0b3a..75fdf650 100644 --- a/api/src/middlewares/TestClient.ts +++ b/api/src/middlewares/TestClient.ts @@ -8,6 +8,20 @@ export default function TestClient(app: Application) { const assetCache = new Map<string, { response: FetchResponse; buffer: Buffer }>(); const indexHTML = fs.readFileSync(path.join(__dirname, "..", "..", "client_test", "index.html"), { encoding: "utf8" }); + var html = indexHTML; + const CDN_ENDPOINT = (Config.get().cdn.endpointClient || Config.get()?.cdn.endpoint || process.env.CDN || "").replace( + /(https?)?(:\/\/?)/g, + "" + ); + const GATEWAY_ENDPOINT = Config.get().gateway.endpointClient || Config.get()?.gateway.endpoint || process.env.GATEWAY || ""; + + if (CDN_ENDPOINT) { + html = html.replace(/CDN_HOST: .+/, `CDN_HOST: \`${CDN_ENDPOINT}\`,`); + } + if (GATEWAY_ENDPOINT) { + html = html.replace(/GATEWAY_ENDPOINT: .+/, `GATEWAY_ENDPOINT: \`${GATEWAY_ENDPOINT}\`,`); + } + app.use("/assets", express.static(path.join(__dirname, "..", "assets"))); app.get("/assets/:file", async (req: Request, res: Response) => { @@ -52,13 +66,6 @@ export default function TestClient(app: Application) { app.get("*", (req: Request, res: Response) => { res.set("Cache-Control", "public, max-age=" + 60 * 60 * 24); res.set("content-type", "text/html"); - var html = indexHTML; - const CDN_ENDPOINT = (Config.get()?.cdn.endpoint || process.env.CDN || "").replace(/(https?)?(:\/\/?)/g, ""); - const GATEWAY_ENDPOINT = Config.get()?.gateway.endpoint || process.env.GATEWAY || ""; - - if (CDN_ENDPOINT && Config.get().cdn.endpointClient) html = html.replace(/CDN_HOST: .+/, `CDN_HOST: "${CDN_ENDPOINT}",`); - if (GATEWAY_ENDPOINT && Config.get().gateway.endpointClient) - html = html.replace(/GATEWAY_ENDPOINT: .+/, `GATEWAY_ENDPOINT: "${GATEWAY_ENDPOINT}",`); res.send(html); }); |