Skip to content

Build your personal knowledge base with Trilium Notes

fix(server): @fs proxy not working correctly

Elian Dorand06b2c4c0024
diff --git a/apps/server/src/routes/assets.ts b/apps/server/src/routes/assets.ts
index 74f2e00eb4..e9803d646a 100644
--- a/apps/server/src/routes/assets.ts
+++ b/apps/server/src/routes/assets.ts
@@ -1,4 +1,4 @@
-import assetPath from "../services/asset_path.js";
+import { assetUrlFragment } from "../services/asset_path.js";
import path from "path";
import { fileURLToPath } from "url";
import express from "express";
@@ -25,22 +25,22 @@ async function register(app: express.Application) {
if (!publicUrl) {
throw new Error("Missing TRILIUM_PUBLIC_SERVER");
}
- app.use(assetPath + `/@fs`, proxy(publicUrl, {
- proxyReqPathResolver: (req) => assetPath + `/@fs` + req.url
- }))
+ app.use("/" + assetUrlFragment + `/@fs`, proxy(publicUrl, {
+ proxyReqPathResolver: (req) => "/" + assetUrlFragment + `/@fs` + req.url
+ }));
} else {
- app.use(`/${assetPath}/src`, persistentCacheStatic(path.join(resourceDir, "public", "src")));
- app.use(`/${assetPath}/stylesheets`, persistentCacheStatic(path.join(resourceDir, "public", "stylesheets")));
- app.use(`/${assetPath}/libraries`, persistentCacheStatic(path.join(resourceDir, "public", "libraries")));
- app.use(`/${assetPath}/fonts`, persistentCacheStatic(path.join(resourceDir, "public", "fonts")));
- app.use(`/${assetPath}/translations/`, persistentCacheStatic(path.join(resourceDir, "public", "translations")));
- app.use(`/${assetPath}/images`, persistentCacheStatic(path.join(resourceDir, "assets", "images")));
- app.use(`/${assetPath}/app-dist/doc_notes`, persistentCacheStatic(path.join(resourceDir, "assets", "doc_notes")));
+ app.use(`/${assetUrlFragment}/src`, persistentCacheStatic(path.join(resourceDir, "public", "src")));
+ app.use(`/${assetUrlFragment}/stylesheets`, persistentCacheStatic(path.join(resourceDir, "public", "stylesheets")));
+ app.use(`/${assetUrlFragment}/libraries`, persistentCacheStatic(path.join(resourceDir, "public", "libraries")));
+ app.use(`/${assetUrlFragment}/fonts`, persistentCacheStatic(path.join(resourceDir, "public", "fonts")));
+ app.use(`/${assetUrlFragment}/translations/`, persistentCacheStatic(path.join(resourceDir, "public", "translations")));
+ app.use(`/${assetUrlFragment}/images`, persistentCacheStatic(path.join(resourceDir, "assets", "images")));
+ app.use(`/${assetUrlFragment}/app-dist/doc_notes`, persistentCacheStatic(path.join(resourceDir, "assets", "doc_notes")));
}
app.use(`/assets/vX/fonts`, express.static(path.join(srcRoot, "public/fonts")));
app.use(`/assets/vX/images`, express.static(path.join(srcRoot, "..", "images")));
app.use(`/assets/vX/stylesheets`, express.static(path.join(srcRoot, "public/stylesheets")));
- app.use(`/${assetPath}/libraries`, persistentCacheStatic(path.join(srcRoot, "public/libraries")));
+ app.use(`/${assetUrlFragment}/libraries`, persistentCacheStatic(path.join(srcRoot, "public/libraries")));
app.use(`/assets/vX/libraries`, express.static(path.join(srcRoot, "..", "libraries")));
}
diff --git a/apps/server/src/services/asset_path.ts b/apps/server/src/services/asset_path.ts
index c5d4764e9f..2695d1fc32 100644
--- a/apps/server/src/services/asset_path.ts
+++ b/apps/server/src/services/asset_path.ts
@@ -1,6 +1,7 @@
import packageJson from "../../package.json" with { type: "json" };
import { isDev } from "./utils";
-const assetPath = isDev ? `http://localhost:4200/assets/v${packageJson.version}` : `assets/v${packageJson.version}`;
+export const assetUrlFragment = `assets/v${packageJson.version}`;
+const assetPath = isDev ? `http://localhost:4200/${assetUrlFragment}` : assetUrlFragment;
export default assetPath;