mirror of
https://github.com/zadam/trilium.git
synced 2025-11-02 03:16:11 +01:00
feat(server): serve client directly instead of proxying
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user