Skip to content

Build your personal knowledge base with Trilium Notes

feat(server): serve client directly instead of proxying

Elian Doran278cdf64f2b0
diff --git a/apps/client/vite.config.ts b/apps/client/vite.config.ts
index e22f9e184d..83bc0a6fc7 100644
--- a/apps/client/vite.config.ts
+++ b/apps/client/vite.config.ts
@@ -7,7 +7,6 @@ const assets = [ "assets", "stylesheets", "libraries", "fonts", "translations" ]
export default defineConfig(() => ({
root: __dirname,
- base: "/assets/v0.94.0/app/",
cacheDir: '../../node_modules/.vite/apps/client',
server: {
port: 4200,
diff --git a/apps/server/src/routes/assets.ts b/apps/server/src/routes/assets.ts
index 8c7ee4248c..4b32ce5d95 100644
--- a/apps/server/src/routes/assets.ts
+++ b/apps/server/src/routes/assets.ts
@@ -28,36 +28,6 @@ async function register(app: express.Application) {
if (!publicUrl) {
throw new Error("Missing TRILIUM_PUBLIC_SERVER");
}
-
- const clientProxy = proxy(publicUrl, {
- proxyReqPathResolver: (req) => {
- let url = req.url;
- url = url.replace(/^\/src/, "");
- if (!url.startsWith("/@")) {
- if (!url.startsWith("/package.json")) {
- url = "/src" + url;
- }
- url = url.replace(/\.js$/, ".ts");
- }
- url = `/${assetPath}/app${url}`;
- return url;
- }
- });
-
- function buildAssetProxy(name: string) {
- return proxy(publicUrl!, {
- proxyReqPathResolver: (req) => `/${assetPath}/app/src/${name}/${req.url}`
- });
- }
-
- app.use(`/${assetPath}/app/doc_notes`, persistentCacheStatic(path.join(srcRoot, "assets", "doc_notes")));
- app.use(`/${assetPath}/app`, clientProxy);
- app.use(`/${assetPath}/app-dist`, clientProxy);
- app.use(`/${assetPath}/stylesheets`, buildAssetProxy("stylesheets"));
- app.use(`/${assetPath}/libraries`, buildAssetProxy("libraries"));
- app.use(`/${assetPath}/fonts`, buildAssetProxy("fonts"));
- app.use(`/${assetPath}/translations`, buildAssetProxy("translations"));
- app.use(`/${assetPath}/images`, persistentCacheStatic(path.join(srcRoot, "assets", "images")));
} else {
const clientStaticCache = persistentCacheStatic(path.join(resourceDir, "public"));
app.use(`/${assetPath}/app`, clientStaticCache);
diff --git a/apps/server/src/services/app_path.ts b/apps/server/src/services/app_path.ts
index c0a651a0fe..5e14722bfd 100644
--- a/apps/server/src/services/app_path.ts
+++ b/apps/server/src/services/app_path.ts
@@ -1,4 +1,4 @@
import assetPath from "./asset_path.js";
import { isDev } from "./utils.js";
-export default isDev ? assetPath + "/app" : assetPath + "/app-dist";
+export default isDev ? assetPath + "/src" : assetPath + "/app-dist";
diff --git a/apps/server/src/services/asset_path.ts b/apps/server/src/services/asset_path.ts
index dd81506cd2..014f04f84b 100644
--- a/apps/server/src/services/asset_path.ts
+++ b/apps/server/src/services/asset_path.ts
@@ -1,3 +1,6 @@
import packageJson from "../../package.json" with { type: "json" };
+import { isDev } from "./utils";
-export default `assets/v${packageJson.version}`;
+const assetPath = isDev ? `http://localhost:4200` : `assets/v${packageJson.version}`;
+
+export default assetPath;