feat(cdn): cdn功能优化
这个提交包含在:
@@ -44,7 +44,7 @@ spec:
|
||||
subs_filter_types text/html;
|
||||
subs_filter '<(script|img|link)([^>]*) (src|href)="/' '<$1$2 $3="https://cdn.fillcode.com/dev-cm/' ri;
|
||||
subs_filter 'url\(\/' 'url(https://cdn.fillcode.com/dev-cm/' ri;
|
||||
subs_filter 'Halo' 'FillCode' r;
|
||||
subs_filter '<head>' '<head><script src="/__static/pwa-cdn.js"></script>' ri;
|
||||
hostname: dev.cm
|
||||
path: /
|
||||
pathType: Prefix
|
||||
|
||||
@@ -316,7 +316,7 @@ data:
|
||||
cdnUrl: 'https://cdn.fillcode.com/',
|
||||
serviceWorkerUrl: '/__static/sw-cdn.js',
|
||||
staticRegex: /\.(js|css|png|jpg|jpeg|gif|svg|webp|woff|woff2|ttf|ico)$/,
|
||||
debug: true,
|
||||
debug: false,
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -377,7 +377,7 @@ data:
|
||||
cdnUrl: 'https://cdn.fillcode.com/',
|
||||
serviceWorkerUrl: '/__static/sw-cdn.js',
|
||||
staticRegex: /\.(js|css|png|jpg|jpeg|gif|svg|webp|woff|woff2|ttf|ico)$/,
|
||||
debug: true,
|
||||
debug: false,
|
||||
}
|
||||
|
||||
// 监听配置更新消息
|
||||
@@ -434,20 +434,6 @@ data:
|
||||
|
||||
if (!response.ok) throw new Error('Target domain response not ok: ' + response.status)
|
||||
|
||||
// 修复重定向问题
|
||||
if([301, 302, 307, 308].includes(response.status)) {
|
||||
const location = response.headers.get('location')
|
||||
|
||||
// 如果重定向的地址不是CDN地址,或者已经包含了CDN子路径,则返回原始响应
|
||||
if(!location?.startsWith('/') || location.startsWith(`/${cdnPath}`)) return response
|
||||
|
||||
// 否则,重定向到新的CDN地址
|
||||
const redirectUrl = new URL(location, config.cdnUrl + cdnPath)
|
||||
|
||||
if (config.debug) console.log('PWA-CDN: Redirecting to', redirectUrl.href)
|
||||
return Response.redirect(redirectUrl.href, response.status)
|
||||
}
|
||||
|
||||
return response
|
||||
} catch (error) {
|
||||
if (config.debug) console.warn('PWA-CDN: Fallback to original request for', url.href, error)
|
||||
|
||||
@@ -6,31 +6,39 @@ metadata:
|
||||
namespace: infra-net
|
||||
annotations:
|
||||
nginx.ingress.kubernetes.io/use-regex: "true"
|
||||
nginx.ingress.kubernetes.io/rewrite-target: /$2
|
||||
nginx.ingress.kubernetes.io/rewrite-target: "/$3"
|
||||
# 重定向配置
|
||||
nginx.ingress.kubernetes.io/proxy-redirect-from: "/"
|
||||
nginx.ingress.kubernetes.io/proxy-redirect-to: "/$1/"
|
||||
# 添加允许跨域请求
|
||||
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/configuration-snippet: |
|
||||
more_set_headers "Set-Cookie $sent_http_set_cookie; SameSite=None; Secure";
|
||||
spec:
|
||||
ingressClassName: nginx
|
||||
rules:
|
||||
- host: cdn.fillcode.com
|
||||
http:
|
||||
paths:
|
||||
- path: /dev-cm(/|$)(.*)
|
||||
- path: /(dev-cm)(/|$)(.*)
|
||||
pathType: ImplementationSpecific
|
||||
backend:
|
||||
service:
|
||||
name: cdn-halo
|
||||
port:
|
||||
number: 80
|
||||
- path: /git-dev-cm(/|$)(.*)
|
||||
- path: /(git-dev-cm)(/|$)(.*)
|
||||
pathType: ImplementationSpecific
|
||||
backend:
|
||||
service:
|
||||
name: cdn-gitea-http
|
||||
port:
|
||||
number: 3000
|
||||
- path: /monitor-dev-cm(/|$)(.*)
|
||||
- path: /(monitor-dev-cm)(/|$)(.*)
|
||||
pathType: ImplementationSpecific
|
||||
backend:
|
||||
service:
|
||||
|
||||
@@ -5,7 +5,7 @@ const pwaCdnConfig = {
|
||||
cdnUrl: 'https://cdn.fillcode.com/',
|
||||
serviceWorkerUrl: '/__static/sw-cdn.js',
|
||||
staticRegex: /\.(js|css|png|jpg|jpeg|gif|svg|webp|woff|woff2|ttf|ico)$/,
|
||||
debug: true,
|
||||
debug: false,
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,7 +5,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)$/,
|
||||
debug: true,
|
||||
debug: false,
|
||||
}
|
||||
|
||||
// 监听配置更新消息
|
||||
@@ -62,20 +62,6 @@ async function handleStaticResource(request, url) {
|
||||
|
||||
if (!response.ok) throw new Error('Target domain response not ok: ' + response.status)
|
||||
|
||||
// 修复重定向问题
|
||||
if([301, 302, 307, 308].includes(response.status)) {
|
||||
const location = response.headers.get('location')
|
||||
|
||||
// 如果重定向的地址不是CDN地址,或者已经包含了CDN子路径,则返回原始响应
|
||||
if(!location?.startsWith('/') || location.startsWith(`/${cdnPath}`)) return response
|
||||
|
||||
// 否则,重定向到新的CDN地址
|
||||
const redirectUrl = new URL(location, config.cdnUrl + cdnPath)
|
||||
|
||||
if (config.debug) console.log('PWA-CDN: Redirecting to', redirectUrl.href)
|
||||
return Response.redirect(redirectUrl.href, response.status)
|
||||
}
|
||||
|
||||
return response
|
||||
} catch (error) {
|
||||
if (config.debug) console.warn('PWA-CDN: Fallback to original request for', url.href, error)
|
||||
|
||||
在新议题中引用
屏蔽一个用户