feat(cdn): cdn完善
这个提交包含在:
@@ -4,7 +4,7 @@
|
||||
let config = {
|
||||
cdnUrl: 'https://cdn.fillcode.com/',
|
||||
serviceWorkerUrl: '/__static/sw-cdn.js',
|
||||
staticRegex: /\.(js|css|png|jpg|jpeg|gif|svg|webp|woff|woff2|ttf|ico)$/,
|
||||
staticRegex: /(.*\.(css|js|png|jpg|jpeg|gif|svg|webp|ico|woff|woff2|ttf|eot)|avatars[^/]+)$/,
|
||||
debug: false,
|
||||
}
|
||||
|
||||
@@ -54,17 +54,19 @@ async function handleStaticResource(request, url) {
|
||||
if (config.debug) console.log('PWA-CDN:', url.href, '->', targetUrl)
|
||||
|
||||
try {
|
||||
// 创建新请求,保留原始缓存策略
|
||||
// 创建新请求
|
||||
const newRequest = new Request(targetUrl, {
|
||||
...request,
|
||||
mode: 'cors',
|
||||
credentials: 'include',
|
||||
redirect: 'manual',
|
||||
})
|
||||
|
||||
// 请求目标域名,浏览器会自动处理缓存
|
||||
const response = await fetch(newRequest)
|
||||
|
||||
if (!response.ok) throw new Error('Target domain response not ok: ' + response.status)
|
||||
// 当遇到非2XX返回时 全部回退原始请求 防止鉴权、重定向等问题
|
||||
if (response.status < 200 || response.status >= 300) throw new Error('PWA-CDN: Non-2xx response detected')
|
||||
|
||||
return response
|
||||
} catch (error) {
|
||||
|
||||
在新议题中引用
屏蔽一个用户