diff --git a/.env b/.env index 8c40928..c736610 100644 --- a/.env +++ b/.env @@ -1,5 +1,6 @@ VUE_APP_APIBASE='https://77.cocogoat.work' VUE_APP_APIBASECN='https://77.cocogoat.cn' -VUE_APP_SWENTRANCE='https://cocogoat.cn/resources/entrance.html' +VUE_APP_SWENTRANCE='https://77.cocogoat.cn/ssr/gi-entrance' VUE_APP_SENTRY='https://c6474900f75a46948250b5f47beda2e2@77.cocogoat.work/sigh/0' -VUE_APP_CLIENT_MIN_VER=1.2.5 \ No newline at end of file +VUE_APP_CLIENT_MIN_VER=1.2.5 +VUE_APP_BASE_URL_LIST='https://cd2-big.cocogoat.cn:11443,https://cd1-big.cocogoat.cn,https://static.cocogoat.cn' \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index 6946882..131cbbb 100644 --- a/src/main.ts +++ b/src/main.ts @@ -63,6 +63,7 @@ declare global { window.$cocogoat = window.$cocogoat || {} const c = { endpoint: '', + entrance: '', build: '', route: process.env.VUE_APP_ROUTER_HASH === 'true' ? 'hash' : 'history', app, @@ -78,6 +79,11 @@ declare global { /// #if !SINGLEFILE window.$cocogoat.sw = loadSW() /// #endif + if (window.$cocogoat.entrance) { + const indexJsonUrl = window.$cocogoat.entrance + const cdnBaseUrl = indexJsonUrl.replace(/\/[^/]*$/, '/') + __webpack_public_path__ = cdnBaseUrl + } })() // 检查连续刷新 diff --git a/src/typings/global.ts b/src/typings/global.ts index 47d55fa..5de4915 100644 --- a/src/typings/global.ts +++ b/src/typings/global.ts @@ -4,6 +4,9 @@ import type { i18n } from '@/i18n' import type resources from '@/resources' export interface CocogoatGlobal { endpoint: string + entrance: string + region?: 'cn' | 'global' + status?: Record build: string route: 'history' | 'hash' manifest: string diff --git a/src/utils/apibase.ts b/src/utils/apibase.ts index b238838..4f32523 100644 --- a/src/utils/apibase.ts +++ b/src/utils/apibase.ts @@ -19,6 +19,12 @@ export const apibase = async (path = '', region = 'default') => { return apis[region === 'default' ? apiregion : region] + path } export const checkRegion = async (apiregion: string) => { + if (window.$cocogoat.status && window.$cocogoat.region) { + apistatus.value = window.$cocogoat.status.msg + apicolor.value = window.$cocogoat.status.typ + syncstatus.value = window.$cocogoat.status.smsg + return window.$cocogoat.region + } const url = (await apis[apiregion]) + '/status' try { const res = await fetch(url) diff --git a/sw/index.ts b/sw/index.ts index 0497280..759187c 100644 --- a/sw/index.ts +++ b/sw/index.ts @@ -135,6 +135,14 @@ registerRoute( cacheName: cacheName, }), ) +;(process.env.VUE_APP_BASE_URL_LIST || '').split(',').forEach((url: string) => { + registerRoute( + new RegExp(`${url}(.*)`), + new CacheFirst({ + cacheName: cacheName, + }), + ) +}) // networkfirst for jsons registerRoute(