feat(cdn): cdn完善
这个提交包含在:
@@ -42,6 +42,12 @@ spec:
|
|||||||
className: nginx
|
className: nginx
|
||||||
annotations:
|
annotations:
|
||||||
nginx.ingress.kubernetes.io/proxy-body-size: "50m"
|
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:
|
hosts:
|
||||||
- host: git.dev.cm
|
- host: git.dev.cm
|
||||||
paths:
|
paths:
|
||||||
|
|||||||
@@ -32,6 +32,14 @@ spec:
|
|||||||
ingress:
|
ingress:
|
||||||
enabled: true
|
enabled: true
|
||||||
ingressClassName: nginx
|
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:
|
hosts:
|
||||||
- monitor.dev.cm
|
- monitor.dev.cm
|
||||||
paths:
|
paths:
|
||||||
|
|||||||
@@ -376,7 +376,7 @@ data:
|
|||||||
let config = {
|
let config = {
|
||||||
cdnUrl: 'https://cdn.fillcode.com/',
|
cdnUrl: 'https://cdn.fillcode.com/',
|
||||||
serviceWorkerUrl: '/__static/sw-cdn.js',
|
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,
|
debug: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -426,13 +426,19 @@ data:
|
|||||||
if (config.debug) console.log('PWA-CDN:', url.href, '->', targetUrl)
|
if (config.debug) console.log('PWA-CDN:', url.href, '->', targetUrl)
|
||||||
|
|
||||||
try {
|
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)
|
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
|
return response
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -14,9 +14,11 @@ metadata:
|
|||||||
nginx.ingress.kubernetes.io/enable-cors: "true"
|
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-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/cors-allow-credentials: "true"
|
||||||
nginx.ingress.kubernetes.io/proxy-cookie-domain: "~^(.+)$ cdn.fillcode.com"
|
# cookie配置
|
||||||
nginx.ingress.kubernetes.io/proxy-cookie-path: "~^/(.*)$ /$1"
|
nginx.ingress.kubernetes.io/proxy-cookie-domain: "* cdn.fillcode.com"
|
||||||
nginx.ingress.kubernetes.io/proxy-cookie-flags: "* Secure SameSite=None"
|
nginx.ingress.kubernetes.io/proxy-cookie-path: "/ /$1"
|
||||||
|
nginx.ingress.kubernetes.io/configuration-snippet: |
|
||||||
|
proxy_cookie_flags ~ SameSite=None Secure;
|
||||||
spec:
|
spec:
|
||||||
ingressClassName: nginx
|
ingressClassName: nginx
|
||||||
rules:
|
rules:
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
let config = {
|
let config = {
|
||||||
cdnUrl: 'https://cdn.fillcode.com/',
|
cdnUrl: 'https://cdn.fillcode.com/',
|
||||||
serviceWorkerUrl: '/__static/sw-cdn.js',
|
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,
|
debug: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,17 +54,19 @@ async function handleStaticResource(request, url) {
|
|||||||
if (config.debug) console.log('PWA-CDN:', url.href, '->', targetUrl)
|
if (config.debug) console.log('PWA-CDN:', url.href, '->', targetUrl)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 创建新请求,保留原始缓存策略
|
// 创建新请求
|
||||||
const newRequest = new Request(targetUrl, {
|
const newRequest = new Request(targetUrl, {
|
||||||
...request,
|
...request,
|
||||||
mode: 'cors',
|
mode: 'cors',
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
|
redirect: 'manual',
|
||||||
})
|
})
|
||||||
|
|
||||||
// 请求目标域名,浏览器会自动处理缓存
|
// 请求目标域名,浏览器会自动处理缓存
|
||||||
const response = await fetch(newRequest)
|
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
|
return response
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
在新议题中引用
屏蔽一个用户