mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-04 23:18:44 +08:00
Merge pull request #453 from DDSRem-Dev/v2
This commit is contained in:
@@ -80,9 +80,9 @@ async function fetchRemoteModules(): Promise<RemoteModule[]> {
|
|||||||
* @param modules 远程模块列表
|
* @param modules 远程模块列表
|
||||||
*/
|
*/
|
||||||
function injectRemoteModule(module: RemoteModule): void {
|
function injectRemoteModule(module: RemoteModule): void {
|
||||||
// 从浏览器地址栏获取当前地址前缀
|
// 与 API 请求一致:使用 origin + pathname 作为前缀,子路径代理时 pathname 含 /mp 等
|
||||||
const baseUrl = new URL(window.location.href)
|
const baseUrl = new URL(window.location.href)
|
||||||
// 环境变量
|
const pathBase = baseUrl.pathname.replace(/\/$/, '') || ''
|
||||||
let apiBase = import.meta.env.VITE_API_BASE_URL
|
let apiBase = import.meta.env.VITE_API_BASE_URL
|
||||||
if (apiBase.startsWith('/')) {
|
if (apiBase.startsWith('/')) {
|
||||||
apiBase = apiBase.slice(1)
|
apiBase = apiBase.slice(1)
|
||||||
@@ -90,8 +90,10 @@ function injectRemoteModule(module: RemoteModule): void {
|
|||||||
if (apiBase.endsWith('/')) {
|
if (apiBase.endsWith('/')) {
|
||||||
apiBase = apiBase.slice(0, -1)
|
apiBase = apiBase.slice(0, -1)
|
||||||
}
|
}
|
||||||
|
const pathWithoutLeadingSlash = module.url.startsWith('/') ? module.url.slice(1) : module.url
|
||||||
|
const remoteEntryUrl = `${baseUrl.origin}${pathBase}/${apiBase}/${pathWithoutLeadingSlash}`
|
||||||
__federation_method_setRemote(module.id, {
|
__federation_method_setRemote(module.id, {
|
||||||
url: () => Promise.resolve(`${baseUrl.origin}/${apiBase}${module.url}`),
|
url: () => Promise.resolve(remoteEntryUrl),
|
||||||
format: 'esm',
|
format: 'esm',
|
||||||
from: 'vite',
|
from: 'vite',
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user