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
@@ -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