/** @typedef {ReturnType<import('./registry.mjs').parseRegistry>} Registry */
|
/** @typedef {Registry['plugins'][number]} RegistryPlugin */
|
|
/** @param {Registry} registry @param {{ host: string, port: number }} options */
|
export function createGatewayConfig(registry, options) {
|
/** @type {Record<string, { changeOrigin: boolean, target: string, ws?: boolean }>} */
|
const proxy = {};
|
for (const plugin of registry.plugins) {
|
const httpTarget = `http://127.0.0.1:${plugin.devPort}`;
|
proxy[`/onlyoffice-plugins/${registry.release}/${plugin.code}`] = { changeOrigin: true, target: httpTarget, ws: true };
|
}
|
proxy['/onlyoffice-sdk'] = { changeOrigin: true, target: `http://127.0.0.1:${registry.plugins[0].devPort}` };
|
return /** @type {import('vite').UserConfig} */ ({
|
appType: 'custom',
|
server: { host: options.host, port: options.port, proxy, strictPort: true },
|
});
|
}
|
|
/** @param {RegistryPlugin} plugin @param {{ gatewayPort: number, publicHost: string }} options */
|
export function createPluginEnvironment(plugin, options) {
|
return {
|
ONLYOFFICE_PLUGIN_DEV_HOST: '127.0.0.1',
|
ONLYOFFICE_PLUGIN_DEV_PORT: String(plugin.devPort),
|
ONLYOFFICE_PLUGIN_HMR_CLIENT_PORT: String(options.gatewayPort),
|
ONLYOFFICE_PLUGIN_HMR_HOST: options.publicHost,
|
ONLYOFFICE_PLUGIN_HMR_PATH: `/__hmr/${plugin.code}`,
|
ONLYOFFICE_PLUGIN_PUBLIC_HOST: options.publicHost,
|
};
|
}
|