Skip to content

Commit

Permalink
refactor: 调整后端插件路由插件url策略,以自适应后端服务变更
Browse files Browse the repository at this point in the history
  • Loading branch information
moonrailgun committed Feb 19, 2022
1 parent f274fc6 commit c0d1867
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` 目录即可。


Expand Down
11 changes: 10 additions & 1 deletion shared/cache/cache.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getServiceUrl } from '../manager/service';
import { ChatConverseInfo, fetchConverseInfo } from '../model/converse';
import { findGroupInviteByCode, GroupInvite } from '../model/group';
import {
Expand Down Expand Up @@ -62,7 +63,15 @@ export async function getCachedRegistryPlugins(): Promise<PluginManifest[]> {
() =>
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]),
{
Expand Down
2 changes: 1 addition & 1 deletion shared/model/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export async function fetchRegistryPlugins(): Promise<PluginManifest[]> {
*
* 后端固定
*/
export async function fetchServiceRegistryPlugins() {
export async function fetchServiceRegistryPlugins(): Promise<PluginManifest[]> {
const { data } = await request.get('/registry.json');

return data;
Expand Down

0 comments on commit c0d1867

Please sign in to comment.