From c0d186770c9466fb7a125d940f1efdb4485f07a1 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Sun, 20 Feb 2022 00:06:54 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E8=B0=83=E6=95=B4=E5=90=8E?= =?UTF-8?q?=E7=AB=AF=E6=8F=92=E4=BB=B6=E8=B7=AF=E7=94=B1=E6=8F=92=E4=BB=B6?= =?UTF-8?q?url=E7=AD=96=E7=95=A5=EF=BC=8C=E4=BB=A5=E8=87=AA=E9=80=82?= =?UTF-8?q?=E5=BA=94=E5=90=8E=E7=AB=AF=E6=9C=8D=E5=8A=A1=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 ++++- shared/cache/cache.ts | 11 ++++++++++- shared/model/plugin.ts | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) 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;