forked from lobehub/lobe-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 fix: fix
PLUGINS_INDEX_URL
not working (lobehub#793)
- Loading branch information
Showing
9 changed files
with
63 additions
and
37 deletions.
There are no files selected for viewing
6 changes: 4 additions & 2 deletions
6
src/app/api/plugins/route.ts → src/app/api/plugin/gateway/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import { createGatewayOnEdgeRuntime } from '@lobehub/chat-plugins-gateway'; | ||
|
||
import { PLUGINS_INDEX_URL } from '@/const/url'; | ||
import { getServerConfig } from '@/config/server'; | ||
|
||
export const POST = createGatewayOnEdgeRuntime({ pluginsIndexUrl: PLUGINS_INDEX_URL }); | ||
const pluginsIndexUrl = getServerConfig().PLUGINS_INDEX_URL; | ||
|
||
export const POST = createGatewayOnEdgeRuntime({ pluginsIndexUrl }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import urlJoin from 'url-join'; | ||
|
||
import { getServerConfig } from '@/config/server'; | ||
import { DEFAULT_LANG, checkLang } from '@/const/locale'; | ||
import { Locales } from '@/locales/resources'; | ||
|
||
export class PluginStore { | ||
private readonly baseUrl: string; | ||
|
||
constructor(baseUrl?: string) { | ||
this.baseUrl = baseUrl || getServerConfig().PLUGINS_INDEX_URL; | ||
} | ||
|
||
getPluginIndexUrl = (lang: Locales = DEFAULT_LANG) => { | ||
if (checkLang(lang)) return this.baseUrl; | ||
|
||
return urlJoin(this.baseUrl, `index.${lang}.json`); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { DEFAULT_LANG } from '@/const/locale'; | ||
|
||
import { PluginStore } from './Store'; | ||
|
||
export const runtime = 'edge'; | ||
|
||
export const GET = async (req: Request) => { | ||
const locale = new URL(req.url).searchParams.get('locale'); | ||
|
||
const pluginStore = new PluginStore(); | ||
|
||
let res: Response; | ||
|
||
res = await fetch(pluginStore.getPluginIndexUrl(locale as any)); | ||
|
||
if (res.status === 404) { | ||
res = await fetch(pluginStore.getPluginIndexUrl(DEFAULT_LANG)); | ||
} | ||
|
||
return res; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters