summary refs log tree commit diff
path: root/src/api/middlewares/TestClient.ts
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2022-08-13 02:00:50 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2022-08-13 22:00:55 +0200
commit5e86d7ab9c5200d794c3adb2b422d20a2aefd2ce (patch)
tree0a4b23ee96862077b21dea20cf71205709e15f7c /src/api/middlewares/TestClient.ts
parenttry to update build script (diff)
downloadserver-5e86d7ab9c5200d794c3adb2b422d20a2aefd2ce.tar.xz
restructure to single project
Diffstat (limited to '')
-rw-r--r--src/api/middlewares/TestClient.ts (renamed from api/src/middlewares/TestClient.ts)16
1 files changed, 9 insertions, 7 deletions
diff --git a/api/src/middlewares/TestClient.ts b/src/api/middlewares/TestClient.ts

index 4fe631cb..a47ff396 100644 --- a/api/src/middlewares/TestClient.ts +++ b/src/api/middlewares/TestClient.ts
@@ -7,11 +7,13 @@ import { Config } from "@fosscord/util"; import { AssetCacheItem } from "../util/entities/AssetCacheItem" import { green } from "picocolors"; +const AssetsPath = path.join(__dirname, "..", "..", "..", "assets") + export default function TestClient(app: Application) { const agent = new ProxyAgent(); //build client page - let html = fs.readFileSync(path.join(__dirname, "..", "..", "client_test", "index.html"), { encoding: "utf8" }); + let html = fs.readFileSync(path.join(AssetsPath, "index.html"), { encoding: "utf8" }); html = applyEnv(html); html = applyInlinePlugins(html); html = applyPlugins(html); @@ -19,7 +21,7 @@ export default function TestClient(app: Application) { //load asset cache let newAssetCache: Map<string, AssetCacheItem> = new Map<string, AssetCacheItem>(); - let assetCacheDir = path.join(__dirname, "..", "..", "assets", "cache"); + let assetCacheDir = path.join(AssetsPath, "cache"); if(process.env.ASSET_CACHE_DIR) assetCacheDir = process.env.ASSET_CACHE_DIR @@ -32,7 +34,7 @@ export default function TestClient(app: Application) { newAssetCache = new Map<string, AssetCacheItem>(Object.entries(JSON.parse(rawdata.toString()))); } - app.use("/assets", express.static(path.join(__dirname, "..", "..", "assets"))); + app.use("/assets", express.static(path.join(AssetsPath))); app.get("/assets/:file", async (req: Request, res: Response) => { delete req.headers.host; let response: FetchResponse; @@ -113,7 +115,7 @@ function applyEnv(html: string): string { function applyPlugins(html: string): string { // plugins - let files = fs.readdirSync(path.join(__dirname, "..", "..", "assets", "plugins")); + let files = fs.readdirSync(path.join(AssetsPath, "plugins")); let plugins = ""; files.forEach(x =>{if(x.endsWith(".js")) plugins += `<script src='/assets/plugins/${x}'></script>\n`; }); return html.replaceAll("<!-- plugin marker -->", plugins); @@ -121,7 +123,7 @@ function applyPlugins(html: string): string { function applyInlinePlugins(html: string): string{ // inline plugins - let files = fs.readdirSync(path.join(__dirname, "..", "..", "assets", "inline-plugins")); + let files = fs.readdirSync(path.join(AssetsPath, "inline-plugins")); let plugins = ""; files.forEach(x =>{if(x.endsWith(".js")) plugins += `<script src='/assets/inline-plugins/${x}'></script>\n\n`; }); return html.replaceAll("<!-- inline plugin marker -->", plugins); @@ -129,9 +131,9 @@ function applyInlinePlugins(html: string): string{ function applyPreloadPlugins(html: string): string{ //preload plugins - let files = fs.readdirSync(path.join(__dirname, "..", "..", "assets", "preload-plugins")); + let files = fs.readdirSync(path.join(AssetsPath, "preload-plugins")); let plugins = ""; - files.forEach(x =>{if(x.endsWith(".js")) plugins += `<script>${fs.readFileSync(path.join(__dirname, "..", "..", "assets", "preload-plugins", x))}</script>\n`; }); + files.forEach(x =>{if(x.endsWith(".js")) plugins += `<script>${fs.readFileSync(path.join(AssetsPath, "preload-plugins", x))}</script>\n`; }); return html.replaceAll("<!-- preload plugin marker -->", plugins); }