Skip to content

Commit

Permalink
✨ feat: dynamic cdn url & prerendered status
Browse files Browse the repository at this point in the history
  • Loading branch information
xytoki committed Aug 8, 2024
1 parent 513c92b commit 37cf0a0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
5 changes: 3 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -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://[email protected]/sigh/0'
VUE_APP_CLIENT_MIN_VER=1.2.5
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'
6 changes: 6 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}
})()

// 检查连续刷新
Expand Down
3 changes: 3 additions & 0 deletions src/typings/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import type { i18n } from '@/i18n'
import type resources from '@/resources'
export interface CocogoatGlobal<T> {
endpoint: string
entrance: string
region?: 'cn' | 'global'
status?: Record<string, string>
build: string
route: 'history' | 'hash'
manifest: string
Expand Down
6 changes: 6 additions & 0 deletions src/utils/apibase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions sw/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 37cf0a0

Please sign in to comment.