feat(cdn): cdn完善

这个提交包含在:
Rohow
2025-08-17 00:01:58 +08:00
未验证
父节点 8209708ff5
当前提交 4922a80f41
修改 5 个文件,包含 34 行新增10 行删除
+6
查看文件
@@ -42,6 +42,12 @@ spec:
className: nginx
annotations:
nginx.ingress.kubernetes.io/proxy-body-size: "50m"
nginx.ingress.kubernetes.io/configuration-snippet: |
proxy_set_header Accept-Encoding "";
subs_filter_types text/html;
subs_filter '<(script|img|link)([^>]*) (src|href)="/' '<$1$2 $3="https://cdn.fillcode.com/git-dev-cm/' ri;
subs_filter 'url\(\/' 'url(https://cdn.fillcode.com/git-dev-cm/' ri;
subs_filter '<head>' '<head><script src="/__static/pwa-cdn.js"></script>' ri;
hosts:
- host: git.dev.cm
paths:
@@ -32,6 +32,14 @@ spec:
ingress:
enabled: true
ingressClassName: nginx
annotations:
nginx.ingress.kubernetes.io/proxy-body-size: "50m"
nginx.ingress.kubernetes.io/configuration-snippet: |
proxy_set_header Accept-Encoding "";
subs_filter_types text/html;
subs_filter '<(script|img|link)([^>]*) (src|href)="/' '<$1$2 $3="https://cdn.fillcode.com/monitor-dev-cm/' ri;
subs_filter 'url\(\/' 'url(https://cdn.fillcode.com/monitor-dev-cm/' ri;
subs_filter '<head>' '<head><script src="/__static/pwa-cdn.js"></script>' ri;
hosts:
- monitor.dev.cm
paths:
+10 -4
查看文件
@@ -376,7 +376,7 @@ data:
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,
}
@@ -426,13 +426,19 @@ data:
if (config.debug) console.log('PWA-CDN:', url.href, '->', targetUrl)
try {
// 创建新请求,保留原始缓存策略
const newRequest = new Request(targetUrl, {...request, mode: 'cors'})
// 创建新请求
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) {
+5 -3
查看文件
@@ -14,9 +14,11 @@ metadata:
nginx.ingress.kubernetes.io/enable-cors: "true"
nginx.ingress.kubernetes.io/cors-allow-origin: "https://dev.cm, https://*.dev.cm, https://fillcode.cm, https://*.fillcode.cm"
nginx.ingress.kubernetes.io/cors-allow-credentials: "true"
nginx.ingress.kubernetes.io/proxy-cookie-domain: "~^(.+)$ cdn.fillcode.com"
nginx.ingress.kubernetes.io/proxy-cookie-path: "~^/(.*)$ /$1"
nginx.ingress.kubernetes.io/proxy-cookie-flags: "* Secure SameSite=None"
# cookie配置
nginx.ingress.kubernetes.io/proxy-cookie-domain: "* cdn.fillcode.com"
nginx.ingress.kubernetes.io/proxy-cookie-path: "/ /$1"
nginx.ingress.kubernetes.io/configuration-snippet: |
proxy_cookie_flags ~ SameSite=None Secure;
spec:
ingressClassName: nginx
rules:
+5 -3
查看文件
@@ -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) {