feat: support deploying pi-web under an arbitrary base path

Make all browser-facing API paths and WebSocket URLs relative so that
vite's <base href> can resolve them correctly when pi-web is served
from a subpath (e.g. /ai or /test/ai).

Also introduce PI_WEB_BASE_PATH so the server can generate plugin
module URLs that include the base path.
This commit is contained in:
chenyimeng
2026-07-12 23:27:43 +02:00
committed by Federico Jaramillo Martinez
parent d72b14f40a
commit 27af5a70ad
11 changed files with 77 additions and 68 deletions
+6 -1
View File
@@ -50,6 +50,11 @@ interface PiWebPluginServiceOptions {
configProvider?: () => PiWebConfig;
}
function piWebBasePath(): string {
const basePath = process.env["PI_WEB_BASE_PATH"] ?? "";
return basePath.replace(/\/$/u, "");
}
interface LocalPluginRoot {
path: string;
source: string;
@@ -135,7 +140,7 @@ export class PiWebPluginService {
private pluginInfo(plugin: PluginRecord, config: PiWebConfig): PiWebPluginInfo {
return {
id: plugin.id,
module: `/pi-web-plugins/${encodeURIComponent(plugin.id)}/${plugin.entryFile}?${pluginModuleQuery(plugin)}`,
module: `${piWebBasePath()}/pi-web-plugins/${encodeURIComponent(plugin.id)}/${plugin.entryFile}?${pluginModuleQuery(plugin)}`,
source: plugin.source,
scope: plugin.scope,
machineSpecific: plugin.machineSpecific,