2024-07-18 21:35:17 +03:00
|
|
|
import assetPath from "../services/asset_path.js";
|
2024-07-18 21:37:45 +03:00
|
|
|
import path from "path";
|
2024-07-19 00:18:35 +03:00
|
|
|
import { fileURLToPath } from "url";
|
2024-07-18 21:37:45 +03:00
|
|
|
import express from "express";
|
2024-07-18 21:35:17 +03:00
|
|
|
import env from "../services/env.js";
|
2025-01-13 23:18:10 +02:00
|
|
|
import type serveStatic from "serve-static";
|
2024-12-14 10:05:38 +02:00
|
|
|
|
2024-04-07 14:02:52 +03:00
|
|
|
const persistentCacheStatic = (root: string, options?: serveStatic.ServeStaticOptions<express.Response<any, Record<string, any>>>) => {
|
2023-05-07 15:23:46 +02:00
|
|
|
if (!env.isDev()) {
|
|
|
|
options = {
|
2025-01-09 18:07:02 +02:00
|
|
|
maxAge: "1y",
|
2023-05-07 15:23:46 +02:00
|
|
|
...options
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return express.static(root, options);
|
|
|
|
};
|
|
|
|
|
2024-12-19 18:16:46 +02:00
|
|
|
async function register(app: express.Application) {
|
2025-01-09 18:07:02 +02:00
|
|
|
const srcRoot = path.join(path.dirname(fileURLToPath(import.meta.url)), "..");
|
2024-12-14 10:10:10 +02:00
|
|
|
if (env.isDev()) {
|
2025-01-09 18:07:02 +02:00
|
|
|
const webpack = (await import("webpack")).default;
|
|
|
|
const webpackMiddleware = (await import("webpack-dev-middleware")).default;
|
|
|
|
const productionConfig = (await import("../../webpack.config.js")).default;
|
|
|
|
|
|
|
|
const frontendCompiler = webpack({
|
|
|
|
mode: "development",
|
|
|
|
entry: productionConfig.entry,
|
|
|
|
module: productionConfig.module,
|
|
|
|
resolve: productionConfig.resolve,
|
|
|
|
devtool: productionConfig.devtool,
|
|
|
|
target: productionConfig.target
|
|
|
|
});
|
|
|
|
|
|
|
|
app.use(`/${assetPath}/app`, webpackMiddleware(frontendCompiler));
|
2024-12-14 10:10:10 +02:00
|
|
|
} else {
|
2025-01-09 18:07:02 +02:00
|
|
|
app.use(`/${assetPath}/app`, persistentCacheStatic(path.join(srcRoot, "public/app")));
|
2024-12-14 10:10:10 +02:00
|
|
|
}
|
2025-01-09 18:07:02 +02:00
|
|
|
app.use(`/${assetPath}/app-dist`, persistentCacheStatic(path.join(srcRoot, "public/app-dist")));
|
|
|
|
app.use(`/${assetPath}/fonts`, persistentCacheStatic(path.join(srcRoot, "public/fonts")));
|
|
|
|
app.use(`/assets/vX/fonts`, express.static(path.join(srcRoot, "public/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, "public/stylesheets")));
|
|
|
|
app.use(`/assets/vX/stylesheets`, express.static(path.join(srcRoot, "public/stylesheets")));
|
|
|
|
app.use(`/${assetPath}/libraries`, persistentCacheStatic(path.join(srcRoot, "..", "libraries")));
|
|
|
|
app.use(`/assets/vX/libraries`, express.static(path.join(srcRoot, "..", "libraries")));
|
|
|
|
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/")));
|
2023-11-09 18:21:53 -03:00
|
|
|
|
|
|
|
// KaTeX
|
2025-01-09 18:07:02 +02:00
|
|
|
app.use(`/${assetPath}/node_modules/katex/dist/katex.min.js`, persistentCacheStatic(path.join(srcRoot, "..", "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")));
|
|
|
|
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")));
|
2023-11-09 18:21:53 -03:00
|
|
|
// expose the whole dist folder
|
2025-01-09 18:07:02 +02:00
|
|
|
app.use(`/node_modules/katex/dist/`, express.static(path.join(srcRoot, "..", "node_modules/katex/dist/")));
|
|
|
|
app.use(`/${assetPath}/node_modules/katex/dist/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/katex/dist/")));
|
2023-11-22 19:58:54 +01:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
app.use(`/${assetPath}/node_modules/dayjs/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/dayjs/")));
|
2023-11-22 20:06:44 +01:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
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/")));
|
2023-11-22 20:09:04 +01:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
app.use(`/${assetPath}/node_modules/mermaid/dist/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/mermaid/dist/")));
|
2023-11-22 20:11:41 +01:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
app.use(`/${assetPath}/node_modules/jquery/dist/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/jquery/dist/")));
|
2023-11-22 20:22:16 +01:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
app.use(`/${assetPath}/node_modules/jquery-hotkeys/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/jquery-hotkeys/")));
|
2023-11-22 20:22:16 +01:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
app.use(`/${assetPath}/node_modules/print-this/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/print-this/")));
|
2023-11-22 20:26:20 +01:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
app.use(`/${assetPath}/node_modules/split.js/dist/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/split.js/dist/")));
|
2023-11-22 20:28:17 +01:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
app.use(`/${assetPath}/node_modules/panzoom/dist/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/panzoom/dist/")));
|
2024-08-11 10:07:30 +02:00
|
|
|
|
2024-08-11 01:33:51 +02:00
|
|
|
// i18n
|
2025-01-09 18:07:02 +02:00
|
|
|
app.use(`/${assetPath}/node_modules/i18next/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/i18next/")));
|
|
|
|
app.use(`/${assetPath}/node_modules/i18next-http-backend/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/i18next-http-backend/")));
|
2024-08-11 01:33:51 +02:00
|
|
|
app.use(`/${assetPath}/translations/`, persistentCacheStatic(path.join(srcRoot, "public", "translations/")));
|
2024-07-20 09:32:56 +03:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
app.use(`/${assetPath}/node_modules/eslint/bin/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/eslint/bin/")));
|
2024-08-11 01:20:17 +02:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
app.use(`/${assetPath}/node_modules/jsplumb/dist/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/jsplumb/dist/")));
|
2024-08-11 01:20:17 +02:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
app.use(`/${assetPath}/node_modules/vanilla-js-wheel-zoom/dist/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/vanilla-js-wheel-zoom/dist/")));
|
2024-12-22 15:42:15 +02:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
app.use(`/${assetPath}/node_modules/mark.js/dist/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/mark.js/dist/")));
|
2024-12-22 15:42:15 +02:00
|
|
|
|
2024-08-12 17:41:33 +02:00
|
|
|
// Deprecated, https://www.npmjs.com/package/autocomplete.js?activeTab=readme
|
2025-01-09 18:07:02 +02:00
|
|
|
app.use(`/${assetPath}/node_modules/autocomplete.js/dist/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/autocomplete.js/dist/")));
|
2024-08-11 01:20:17 +02:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
app.use(`/${assetPath}/node_modules/knockout/build/output/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/knockout/build/output/")));
|
2024-08-11 01:20:17 +02:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
app.use(`/${assetPath}/node_modules/normalize.css/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/normalize.css/")));
|
2024-08-11 01:59:50 +02:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
app.use(`/${assetPath}/node_modules/jquery.fancytree/dist/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/jquery.fancytree/dist/")));
|
2024-08-11 01:59:50 +02:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
app.use(`/${assetPath}/node_modules/bootstrap/dist/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/bootstrap/dist/")));
|
2024-08-12 17:41:33 +02:00
|
|
|
|
|
|
|
// CodeMirror
|
2025-01-09 18:07:02 +02:00
|
|
|
app.use(`/${assetPath}/node_modules/codemirror/lib/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/codemirror/lib/")));
|
|
|
|
app.use(`/${assetPath}/node_modules/codemirror/addon/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/codemirror/addon/")));
|
|
|
|
app.use(`/${assetPath}/node_modules/codemirror/mode/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/codemirror/mode/")));
|
|
|
|
app.use(`/${assetPath}/node_modules/codemirror/keymap/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/codemirror/keymap/")));
|
2024-09-01 15:04:47 +03:00
|
|
|
|
|
|
|
app.use(`/${assetPath}/node_modules/mind-elixir/dist/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/mind-elixir/dist/")));
|
2024-12-08 17:07:31 +02:00
|
|
|
app.use(`/${assetPath}/node_modules/@mind-elixir/node-menu/dist/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/@mind-elixir/node-menu/dist/")));
|
2024-10-26 22:57:07 +03:00
|
|
|
app.use(`/${assetPath}/node_modules/@highlightjs/cdn-assets/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/@highlightjs/cdn-assets/")));
|
2025-01-20 19:18:29 +02:00
|
|
|
|
|
|
|
app.use(`/${assetPath}/node_modules/leaflet/dist/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/leaflet/dist/")));
|
2023-11-22 19:58:54 +01:00
|
|
|
}
|
2023-05-07 15:23:46 +02:00
|
|
|
|
2024-07-18 21:42:44 +03:00
|
|
|
export default {
|
2023-05-07 15:23:46 +02:00
|
|
|
register
|
|
|
|
};
|