feat(server): serve client directly instead of proxying

This commit is contained in:
Elian Doran 2025-05-17 00:51:06 +03:00
parent cb381d01c1
commit 278cdf64f2
No known key found for this signature in database
4 changed files with 5 additions and 33 deletions

View File

@ -7,7 +7,6 @@ const assets = [ "assets", "stylesheets", "libraries", "fonts", "translations" ]
export default defineConfig(() => ({ export default defineConfig(() => ({
root: __dirname, root: __dirname,
base: "/assets/v0.94.0/app/",
cacheDir: '../../node_modules/.vite/apps/client', cacheDir: '../../node_modules/.vite/apps/client',
server: { server: {
port: 4200, port: 4200,

View File

@ -28,36 +28,6 @@ async function register(app: express.Application) {
if (!publicUrl) { if (!publicUrl) {
throw new Error("Missing TRILIUM_PUBLIC_SERVER"); 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 { } else {
const clientStaticCache = persistentCacheStatic(path.join(resourceDir, "public")); const clientStaticCache = persistentCacheStatic(path.join(resourceDir, "public"));
app.use(`/${assetPath}/app`, clientStaticCache); app.use(`/${assetPath}/app`, clientStaticCache);

View File

@ -1,4 +1,4 @@
import assetPath from "./asset_path.js"; import assetPath from "./asset_path.js";
import { isDev } from "./utils.js"; import { isDev } from "./utils.js";
export default isDev ? assetPath + "/app" : assetPath + "/app-dist"; export default isDev ? assetPath + "/src" : assetPath + "/app-dist";

View File

@ -1,3 +1,6 @@
import packageJson from "../../package.json" with { type: "json" }; 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;