Skip to content

Build your personal knowledge base with Trilium Notes

refactor(nx/server): fix proxying of stylesheets

Elian Doranb2d051edee6e
diff --git a/apps/client/webpack.config.js b/apps/client/webpack.config.js
index 8a879e40a7..a9f1aad575 100644
--- a/apps/client/webpack.config.js
+++ b/apps/client/webpack.config.js
@@ -42,7 +42,7 @@ module.exports = {
}
],
baseHref: '/',
- assets: ["./src/assets"],
+ assets: ["./src/assets", "./src/stylesheets"],
styles: [],
outputHashing: process.env['NODE_ENV'] === 'production' ? 'all' : 'none',
optimization: process.env['NODE_ENV'] === 'production',
diff --git a/apps/server/src/routes/assets.ts b/apps/server/src/routes/assets.ts
index 685af90cb4..001edb5385 100644
--- a/apps/server/src/routes/assets.ts
+++ b/apps/server/src/routes/assets.ts
@@ -19,11 +19,18 @@ const persistentCacheStatic = (root: string, options?: serveStatic.ServeStaticOp
async function register(app: express.Application) {
const srcRoot = path.join(path.dirname(fileURLToPath(import.meta.url)), "..");
if (isDev) {
- const clientProxy = proxy(process.env.TRILIUM_PUBLIC_SERVER);
+ const publicUrl = process.env.TRILIUM_PUBLIC_SERVER;
+ if (!publicUrl) {
+ throw new Error("Missing TRILIUM_PUBLIC_SERVER");
+ }
+
+ const clientProxy = proxy(publicUrl);
app.use(`/${assetPath}/app/doc_notes`, persistentCacheStatic(path.join(srcRoot, "public/app/doc_notes")));
app.use(`/${assetPath}/app`, clientProxy);
app.use(`/${assetPath}/app-dist`, clientProxy);
- app.use(`/${assetPath}/stylesheets`, persistentCacheStatic(path.join(srcRoot, "../../client/stylesheets")));
+ app.use(`/${assetPath}/stylesheets`, proxy(publicUrl, {
+ proxyReqPathResolver: (req) => "/stylesheets" + req.url
+ }));
app.use(`/${assetPath}/libraries`, persistentCacheStatic(path.join(srcRoot, "../../client/libraries")));
} else {
app.use(`/${assetPath}/app`, persistentCacheStatic(path.join(srcRoot, "public/app")));