summary refs log tree commit diff
path: root/src/api/middlewares/TestClient.ts
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-09-26 12:53:56 +1000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-09-26 12:57:36 +1000
commitfa89b18d95f1639ec600716a2f715d2ab038c770 (patch)
tree6d62b82889dd71baaa9d064914ef61ea0318b484 /src/api/middlewares/TestClient.ts
parentVscode launch config (diff)
downloadserver-fa89b18d95f1639ec600716a2f715d2ab038c770.tar.xz
Rearrange assets a bit, fix anything that uses assets folder
Diffstat (limited to 'src/api/middlewares/TestClient.ts')
-rw-r--r--src/api/middlewares/TestClient.ts18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/api/middlewares/TestClient.ts b/src/api/middlewares/TestClient.ts
index 0bd63eb5..765059c7 100644
--- a/src/api/middlewares/TestClient.ts
+++ b/src/api/middlewares/TestClient.ts
@@ -5,10 +5,12 @@ import fetch, { Response as FetchResponse } from "node-fetch";
 import ProxyAgent from 'proxy-agent';
 import { Config } from "@fosscord/util";
 
+const ASSET_FOLDER_PATH = path.join(__dirname, "..", "..", "..", "assets");
+
 export default function TestClient(app: Application) {
 	const agent = new ProxyAgent();
 	const assetCache = new Map<string, { response: FetchResponse; buffer: Buffer; }>();
-	const indexHTML = fs.readFileSync(path.join(__dirname, "..", "..", "..", "assets", "client_test", "index.html"), { encoding: "utf8" });
+	const indexHTML = fs.readFileSync(path.join(ASSET_FOLDER_PATH, "client_test", "index.html"), { encoding: "utf8" });
 
 	var html = indexHTML;
 	const CDN_ENDPOINT = (Config.get().cdn.endpointClient || Config.get()?.cdn.endpointPublic || process.env.CDN || "").replace(
@@ -24,24 +26,24 @@ export default function TestClient(app: Application) {
 		html = html.replace(/GATEWAY_ENDPOINT: .+/, `GATEWAY_ENDPOINT: \`${GATEWAY_ENDPOINT}\`,`);
 	}
 	// inline plugins
-	var files = fs.readdirSync(path.join(__dirname, "..", "..", "..", "assets", "preload-plugins"));
+	var files = fs.readdirSync(path.join(ASSET_FOLDER_PATH, "preload-plugins"));
 	var 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(ASSET_FOLDER_PATH, "preload-plugins", x))}</script>\n`; });
 	html = html.replaceAll("<!-- preload plugin marker -->", plugins);
 
 	// plugins
-	files = fs.readdirSync(path.join(__dirname, "..", "..", "..", "assets", "plugins"));
+	files = fs.readdirSync(path.join(ASSET_FOLDER_PATH, "plugins"));
 	plugins = "";
 	files.forEach(x => { if (x.endsWith(".js")) plugins += `<script src='/assets/plugins/${x}'></script>\n`; });
 	html = html.replaceAll("<!-- plugin marker -->", plugins);
 	//preload plugins
-	files = fs.readdirSync(path.join(__dirname, "..", "..", "..", "assets", "preload-plugins"));
+	files = fs.readdirSync(path.join(ASSET_FOLDER_PATH, "preload-plugins"));
 	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(ASSET_FOLDER_PATH, "preload-plugins", x))}</script>\n`; });
 	html = html.replaceAll("<!-- preload plugin marker -->", plugins);
 
 
-	app.use("/assets", express.static(path.join(__dirname, "..", "..", "assets")));
+	app.use("/assets", express.static(path.join(ASSET_FOLDER_PATH, "public")));
 
 	app.get("/assets/:file", async (req: Request, res: Response) => {
 		delete req.headers.host;
@@ -90,7 +92,7 @@ export default function TestClient(app: Application) {
 
 		if (!useTestClient) return res.send("Test client is disabled on this instance. Use a stand-alone client to connect this instance.");
 
-		res.send(fs.readFileSync(path.join(__dirname, "..", "..", "client_test", "developers.html"), { encoding: "utf8" }));
+		res.send(fs.readFileSync(path.join(ASSET_FOLDER_PATH, "client_test", "developers.html"), { encoding: "utf8" }));
 	});
 	app.get("*", (req: Request, res: Response) => {
 		const { useTestClient } = Config.get().client;