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);
}
|