mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-10-17 20:20:40 +08:00
feat(server): serve client directly instead of proxying
This commit is contained in:
parent
cb381d01c1
commit
278cdf64f2
@ -7,7 +7,6 @@ const assets = [ "assets", "stylesheets", "libraries", "fonts", "translations" ]
|
||||
|
||||
export default defineConfig(() => ({
|
||||
root: __dirname,
|
||||
base: "/assets/v0.94.0/app/",
|
||||
cacheDir: '../../node_modules/.vite/apps/client',
|
||||
server: {
|
||||
port: 4200,
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user