From 02ff68b6c7e2b45a1a8df74098ca3a1ad56b1b05 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 11 May 2024 10:22:22 +0300 Subject: [PATCH] #12: Fix serving icons --- server/src/routes/assets.ts | 67 +++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/server/src/routes/assets.ts b/server/src/routes/assets.ts index 2af58d006..96339685f 100644 --- a/server/src/routes/assets.ts +++ b/server/src/routes/assets.ts @@ -15,60 +15,63 @@ const persistentCacheStatic = (root: string, options?: serveStatic.ServeStaticOp }; function register(app: express.Application) { - const srcRoot = path.join(__dirname, '..', '..', '..', 'client'); - app.use(`/${assetPath}/app`, persistentCacheStatic(path.join(srcRoot, 'src'))); - app.use(`/${assetPath}/app-dist`, persistentCacheStatic(path.join(srcRoot, 'src-dist'))); - app.use(`/${assetPath}/fonts`, persistentCacheStatic(path.join(srcRoot, 'assets/fonts'))); - app.use(`/assets/vX/fonts`, express.static(path.join(srcRoot, 'assets/fonts'))); - app.use(`/${assetPath}/images`, persistentCacheStatic(path.join(srcRoot, 'images'))); - app.use(`/assets/vX/images`, express.static(path.join(srcRoot, 'images'))); - app.use(`/${assetPath}/stylesheets`, persistentCacheStatic(path.join(srcRoot, 'assets/stylesheets'))); - app.use(`/assets/vX/stylesheets`, express.static(path.join(srcRoot, 'assets/stylesheets'))); - app.use(`/${assetPath}/libraries`, persistentCacheStatic(path.join(srcRoot, 'libraries'))); - app.use(`/assets/vX/libraries`, express.static(path.join(srcRoot, 'libraries'))); + const root = path.join(__dirname, '..', '..', '..'); + const clientRoot = path.join(root, 'client'); + const commonRoot = path.join(root, 'common'); + + app.use(`/${assetPath}/app`, persistentCacheStatic(path.join(clientRoot, 'src'))); + app.use(`/${assetPath}/app-dist`, persistentCacheStatic(path.join(clientRoot, 'src-dist'))); + app.use(`/${assetPath}/fonts`, persistentCacheStatic(path.join(clientRoot, 'assets/fonts'))); + app.use(`/assets/vX/fonts`, express.static(path.join(clientRoot, 'assets/fonts'))); + app.use(`/${assetPath}/images`, persistentCacheStatic(path.join(commonRoot, 'images'))); + app.use(`/assets/vX/images`, express.static(path.join(clientRoot, 'images'))); + app.use(`/${assetPath}/stylesheets`, persistentCacheStatic(path.join(clientRoot, 'assets/stylesheets'))); + app.use(`/assets/vX/stylesheets`, express.static(path.join(clientRoot, 'assets/stylesheets'))); + app.use(`/${assetPath}/libraries`, persistentCacheStatic(path.join(clientRoot, 'libraries'))); + app.use(`/assets/vX/libraries`, express.static(path.join(clientRoot, 'libraries'))); // excalidraw-view mode in shared notes - app.use(`/${assetPath}/node_modules/react/umd/react.production.min.js`, persistentCacheStatic(path.join(srcRoot, 'node_modules/react/umd/react.production.min.js'))); - app.use(`/${assetPath}/node_modules/react/umd/react.development.js`, persistentCacheStatic(path.join(srcRoot, 'node_modules/react/umd/react.development.js'))); - app.use(`/${assetPath}/node_modules/react-dom/umd/react-dom.production.min.js`, persistentCacheStatic(path.join(srcRoot, 'node_modules/react-dom/umd/react-dom.production.min.js'))); - app.use(`/${assetPath}/node_modules/react-dom/umd/react-dom.development.js`, persistentCacheStatic(path.join(srcRoot, 'node_modules/react-dom/umd/react-dom.development.js'))); + app.use(`/${assetPath}/node_modules/react/umd/react.production.min.js`, persistentCacheStatic(path.join(clientRoot, 'node_modules/react/umd/react.production.min.js'))); + app.use(`/${assetPath}/node_modules/react/umd/react.development.js`, persistentCacheStatic(path.join(clientRoot, 'node_modules/react/umd/react.development.js'))); + app.use(`/${assetPath}/node_modules/react-dom/umd/react-dom.production.min.js`, persistentCacheStatic(path.join(clientRoot, 'node_modules/react-dom/umd/react-dom.production.min.js'))); + app.use(`/${assetPath}/node_modules/react-dom/umd/react-dom.development.js`, persistentCacheStatic(path.join(clientRoot, 'node_modules/react-dom/umd/react-dom.development.js'))); // expose the whole dist folder since complete assets are needed in edit and share - app.use(`/node_modules/@excalidraw/excalidraw/dist/`, express.static(path.join(srcRoot, 'node_modules/@excalidraw/excalidraw/dist/'))); - app.use(`/${assetPath}/node_modules/@excalidraw/excalidraw/dist/`, persistentCacheStatic(path.join(srcRoot, 'node_modules/@excalidraw/excalidraw/dist/'))); + app.use(`/node_modules/@excalidraw/excalidraw/dist/`, express.static(path.join(clientRoot, 'node_modules/@excalidraw/excalidraw/dist/'))); + app.use(`/${assetPath}/node_modules/@excalidraw/excalidraw/dist/`, persistentCacheStatic(path.join(clientRoot, 'node_modules/@excalidraw/excalidraw/dist/'))); // KaTeX app.use( `/${assetPath}/node_modules/katex/dist/katex.min.js`, - persistentCacheStatic(path.join(srcRoot, 'node_modules/katex/dist/katex.min.js'))); + persistentCacheStatic(path.join(clientRoot, 'node_modules/katex/dist/katex.min.js'))); app.use( `/${assetPath}/node_modules/katex/dist/contrib/mhchem.min.js`, - persistentCacheStatic(path.join(srcRoot, 'node_modules/katex/dist/contrib/mhchem.min.js'))); + persistentCacheStatic(path.join(clientRoot, 'node_modules/katex/dist/contrib/mhchem.min.js'))); app.use( `/${assetPath}/node_modules/katex/dist/contrib/auto-render.min.js`, - persistentCacheStatic(path.join(srcRoot, 'node_modules/katex/dist/contrib/auto-render.min.js'))); + persistentCacheStatic(path.join(clientRoot, 'node_modules/katex/dist/contrib/auto-render.min.js'))); // expose the whole dist folder app.use(`/node_modules/katex/dist/`, - express.static(path.join(srcRoot, 'node_modules/katex/dist/'))); + express.static(path.join(clientRoot, 'node_modules/katex/dist/'))); app.use(`/${assetPath}/node_modules/katex/dist/`, - persistentCacheStatic(path.join(srcRoot, 'node_modules/katex/dist/'))); + persistentCacheStatic(path.join(clientRoot, 'node_modules/katex/dist/'))); - app.use(`/${assetPath}/node_modules/dayjs/`, persistentCacheStatic(path.join(srcRoot, 'node_modules/dayjs/'))); - app.use(`/${assetPath}/node_modules/force-graph/dist/`, persistentCacheStatic(path.join(srcRoot, 'node_modules/force-graph/dist/'))); + app.use(`/${assetPath}/node_modules/dayjs/`, persistentCacheStatic(path.join(clientRoot, 'node_modules/dayjs/'))); + app.use(`/${assetPath}/node_modules/force-graph/dist/`, persistentCacheStatic(path.join(clientRoot, 'node_modules/force-graph/dist/'))); - app.use(`/${assetPath}/node_modules/boxicons/css/`, persistentCacheStatic(path.join(srcRoot, 'node_modules/boxicons/css/'))); - app.use(`/${assetPath}/node_modules/boxicons/fonts/`, persistentCacheStatic(path.join(srcRoot, 'node_modules/boxicons/fonts/'))); + app.use(`/${assetPath}/node_modules/boxicons/css/`, persistentCacheStatic(path.join(clientRoot, 'node_modules/boxicons/css/'))); + app.use(`/${assetPath}/node_modules/boxicons/fonts/`, persistentCacheStatic(path.join(clientRoot, 'node_modules/boxicons/fonts/'))); - app.use(`/${assetPath}/node_modules/mermaid/dist/`, persistentCacheStatic(path.join(srcRoot, 'node_modules/mermaid/dist/'))); + app.use(`/${assetPath}/node_modules/mermaid/dist/`, persistentCacheStatic(path.join(clientRoot, 'node_modules/mermaid/dist/'))); - app.use(`/${assetPath}/node_modules/jquery/dist/`, persistentCacheStatic(path.join(srcRoot, 'node_modules/jquery/dist/'))); + app.use(`/${assetPath}/node_modules/jquery/dist/`, persistentCacheStatic(path.join(clientRoot, 'node_modules/jquery/dist/'))); - app.use(`/${assetPath}/node_modules/jquery-hotkeys/`, persistentCacheStatic(path.join(srcRoot, 'node_modules/jquery-hotkeys/'))); + app.use(`/${assetPath}/node_modules/jquery-hotkeys/`, persistentCacheStatic(path.join(clientRoot, 'node_modules/jquery-hotkeys/'))); - app.use(`/${assetPath}/node_modules/print-this/`, persistentCacheStatic(path.join(srcRoot, 'node_modules/print-this/'))); + app.use(`/${assetPath}/node_modules/print-this/`, persistentCacheStatic(path.join(clientRoot, 'node_modules/print-this/'))); - app.use(`/${assetPath}/node_modules/split.js/dist/`, persistentCacheStatic(path.join(srcRoot, 'node_modules/split.js/dist/'))); + app.use(`/${assetPath}/node_modules/split.js/dist/`, persistentCacheStatic(path.join(clientRoot, 'node_modules/split.js/dist/'))); - app.use(`/${assetPath}/node_modules/panzoom/dist/`, persistentCacheStatic(path.join(srcRoot, 'node_modules/panzoom/dist/'))); + app.use(`/${assetPath}/node_modules/panzoom/dist/`, persistentCacheStatic(path.join(clientRoot, 'node_modules/panzoom/dist/'))); } export = {