diff --git a/README.md b/README.md index 6dabd730..89788582 100644 --- a/README.md +++ b/README.md @@ -34,9 +34,12 @@ Nightly版 体验地址: [https://nightly.paw.msgbyte.com/](https://nightly.paw. ```bash pnpm install cd web -pnpm build +SERVICE_URL=http://127.0.0.1:11000 pnpm build ``` +环境变量: +- `SERVICE_URL`: 后端服务的地址 + 使用任意方式代理 `web/dist` 目录即可。 diff --git a/shared/cache/cache.ts b/shared/cache/cache.ts index 49babcf5..14f11249 100644 --- a/shared/cache/cache.ts +++ b/shared/cache/cache.ts @@ -1,3 +1,4 @@ +import { getServiceUrl } from '../manager/service'; import { ChatConverseInfo, fetchConverseInfo } from '../model/converse'; import { findGroupInviteByCode, GroupInvite } from '../model/group'; import { @@ -62,7 +63,15 @@ export async function getCachedRegistryPlugins(): Promise { () => Promise.all([ fetchRegistryPlugins().catch(() => []), - fetchServiceRegistryPlugins().catch(() => []), + fetchServiceRegistryPlugins() + .then((list) => + list.map((manifest) => ({ + ...manifest, + // 后端url策略。根据前端的url在获取时自动变更为当前链接的后端地址 + url: String(manifest.url).replace('{BACKEND}', getServiceUrl()), + })) + ) + .catch(() => []), fetchLocalStaticRegistryPlugins().catch(() => []), ]).then(([a, b, c]) => [...a, ...b, ...c]), { diff --git a/shared/model/plugin.ts b/shared/model/plugin.ts index e01a4d8b..a88edb2a 100644 --- a/shared/model/plugin.ts +++ b/shared/model/plugin.ts @@ -65,7 +65,7 @@ export async function fetchRegistryPlugins(): Promise { * * 后端固定 */ -export async function fetchServiceRegistryPlugins() { +export async function fetchServiceRegistryPlugins(): Promise { const { data } = await request.get('/registry.json'); return data;