Cross-origin (5173 vs 4000) blocked the auth cookie from reaching the bridge — every /database slash command request 401'd silently. Two changes: 1. vite.config.ts: add /bridge -> http://localhost:4000 proxy with path rewrite + /bridge-events -> /api/events for SSE. Same-origin = browser sends the auth cookie automatically. 2. bridge-client.ts: resolveBridgeUrl() defaults to /bridge instead of absolute http://localhost:4000. Also adds a VITE_BRIDGE_TOKEN env fallback for dev (the bridge requires Bearer auth and the Docmost session cookie is HttpOnly so JS cannot read it). Patch 021.
88 lines
2.1 KiB
TypeScript
88 lines
2.1 KiB
TypeScript
import { defineConfig, loadEnv } from "vite";
|
|
import react from "@vitejs/plugin-react";
|
|
import * as path from "path";
|
|
|
|
const envPath = path.resolve(process.cwd(), "..", "..");
|
|
|
|
export default defineConfig(({ mode }) => {
|
|
const {
|
|
APP_URL,
|
|
FILE_UPLOAD_SIZE_LIMIT,
|
|
FILE_IMPORT_SIZE_LIMIT,
|
|
DRAWIO_URL,
|
|
CLOUD,
|
|
SUBDOMAIN_HOST,
|
|
COLLAB_URL,
|
|
BILLING_TRIAL_DAYS,
|
|
POSTHOG_HOST,
|
|
POSTHOG_KEY,
|
|
VITE_BRIDGE_TOKEN,
|
|
} = loadEnv(mode, envPath, "");
|
|
|
|
return {
|
|
define: {
|
|
"process.env": {
|
|
APP_URL,
|
|
FILE_UPLOAD_SIZE_LIMIT,
|
|
FILE_IMPORT_SIZE_LIMIT,
|
|
DRAWIO_URL,
|
|
CLOUD,
|
|
SUBDOMAIN_HOST,
|
|
COLLAB_URL,
|
|
BILLING_TRIAL_DAYS,
|
|
POSTHOG_HOST,
|
|
POSTHOG_KEY,
|
|
VITE_BRIDGE_TOKEN,
|
|
},
|
|
APP_VERSION: JSON.stringify(process.env.npm_package_version),
|
|
},
|
|
plugins: [react()],
|
|
build: {
|
|
rolldownOptions: {
|
|
output: {
|
|
codeSplitting: {
|
|
groups: [
|
|
{ name: "vendor-mantine", test: /@mantine/ },
|
|
{ name: "vendor-mermaid", test: /mermaid|cytoscape|elkjs/ },
|
|
{ name: "vendor-excalidraw", test: /excalidraw/ },
|
|
{ name: "vendor-katex", test: /katex/ },
|
|
],
|
|
},
|
|
},
|
|
},
|
|
},
|
|
resolve: {
|
|
alias: {
|
|
"@": "/src",
|
|
},
|
|
},
|
|
server: {
|
|
proxy: {
|
|
"/api": {
|
|
target: APP_URL,
|
|
changeOrigin: false,
|
|
},
|
|
"/socket.io": {
|
|
target: APP_URL,
|
|
ws: true,
|
|
rewriteWsOrigin: true,
|
|
},
|
|
"/collab": {
|
|
target: APP_URL,
|
|
ws: true,
|
|
rewriteWsOrigin: true,
|
|
},
|
|
"/bridge": {
|
|
target: process.env.VITE_BRIDGE_PROXY_TARGET || "http://localhost:4000",
|
|
changeOrigin: true,
|
|
rewrite: (p) => p.replace(/^\/bridge/, ""),
|
|
},
|
|
"/bridge-events": {
|
|
target: process.env.VITE_BRIDGE_PROXY_TARGET || "http://localhost:4000",
|
|
changeOrigin: true,
|
|
rewrite: (p) => p.replace(/^\/bridge-events/, "/api/events"),
|
|
},
|
|
},
|
|
},
|
|
};
|
|
});
|