Archived
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:
committed by
Federico Jaramillo Martinez
parent
d72b14f40a
commit
27af5a70ad
@@ -86,7 +86,7 @@ function rewriteRemotePluginManifest(machineId: string, manifest: RemotePluginMa
|
||||
if (modulePath === undefined) return [];
|
||||
return [{
|
||||
...plugin,
|
||||
module: `/pi-web-plugins/${encodeURIComponent(machineScopedPluginId(machineId, plugin.id))}/${modulePath.path}${modulePath.query}`,
|
||||
module: `${piWebBasePath()}/pi-web-plugins/${encodeURIComponent(machineScopedPluginId(machineId, plugin.id))}/${modulePath.path}${modulePath.query}`,
|
||||
}];
|
||||
}),
|
||||
};
|
||||
@@ -190,6 +190,11 @@ function sendGatewayError(reply: FastifyReply, machineId: string, error: unknown
|
||||
});
|
||||
}
|
||||
|
||||
function piWebBasePath(): string {
|
||||
const basePath = process.env["PI_WEB_BASE_PATH"] ?? "";
|
||||
return basePath.replace(/\/$/u, "");
|
||||
}
|
||||
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return typeof value === "object" && value !== null && !Array.isArray(value);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user