From c2ca34e67e37962c259c41b815880f2c847451b4 Mon Sep 17 00:00:00 2001 From: rohow Date: Mon, 24 Aug 2026 15:57:41 +0800 Subject: [PATCH] feat(apps): add Fillcode website HelmRelease --- flux/apps/helmrelease-fillcode-website.yaml | 25 +++++++++++++++++++ flux/apps/kustomization.yaml | 1 + .../infra-net/configmap-static.yaml | 21 ++++++++-------- 3 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 flux/apps/helmrelease-fillcode-website.yaml diff --git a/flux/apps/helmrelease-fillcode-website.yaml b/flux/apps/helmrelease-fillcode-website.yaml new file mode 100644 index 0000000..7c74e26 --- /dev/null +++ b/flux/apps/helmrelease-fillcode-website.yaml @@ -0,0 +1,25 @@ +apiVersion: helm.toolkit.fluxcd.io/v2 +kind: HelmRelease +metadata: + name: fillcode-website + namespace: apps +spec: + interval: 30m + timeout: 15m + chart: + spec: + chart: website + version: 0.0.1 + sourceRef: + kind: HelmRepository + name: devcm-repo + namespace: infra-gitops + interval: 12h + values: + ingress: + main: + enabled: true + tls: + - hosts: + - fillcode.com + secretName: fillcode-com-crt diff --git a/flux/apps/kustomization.yaml b/flux/apps/kustomization.yaml index 8527a2c..ba5a9c6 100644 --- a/flux/apps/kustomization.yaml +++ b/flux/apps/kustomization.yaml @@ -3,6 +3,7 @@ kind: Kustomization resources: - certificate-fillcode-com.yaml - certificate-sinceai-com.yaml + - helmrelease-fillcode-website.yaml - helmrelease-halo.yaml - ingress-fillcode.yaml - ingress-halo-www.yaml diff --git a/flux/infrastructure/infra-net/configmap-static.yaml b/flux/infrastructure/infra-net/configmap-static.yaml index 19cb96d..7221187 100644 --- a/flux/infrastructure/infra-net/configmap-static.yaml +++ b/flux/infrastructure/infra-net/configmap-static.yaml @@ -392,18 +392,23 @@ data: // 拦截网络请求 self.addEventListener('fetch', e => { const url = new URL(e.request.url) + const cdnPath = self.location.hostname.replace(/\./g, '-') + const cdnPrefix = `/${cdnPath}` + const missingCdnPrefix = url.origin === new URL(config.cdnUrl).origin + && url.pathname !== cdnPrefix + && !url.pathname.startsWith(`${cdnPrefix}/`) // 如果请求不是GET方法,直接返回 if (e.request.method !== 'GET') return - // 如果请求的域名不是当前页面的域名 - if (url.origin !== self.location.origin) return + // 只处理同源资源和缺少当前站点子路径的CDN资源 + if (url.origin !== self.location.origin && !missingCdnPrefix) return // 过滤__static路径下的请求 if (url.pathname.startsWith('/__static/')) return - // 如果请求的路径不匹配静态资源正则表达式,直接返回 - if (!config.staticRegex.test(url.pathname)) return + // 同源请求仍按静态资源规则过滤;CDN缺前缀请求直接修复 + if (!missingCdnPrefix && !config.staticRegex.test(url.pathname)) return // 判断是否是强制需要同源请求 const requiresSameOrigin = ['worker', 'sharedworker', 'serviceworker'].includes(e.request.destination) @@ -412,15 +417,11 @@ data: if (requiresSameOrigin) return // 开始处理静态资源请求 - e.respondWith(handleStaticResource(e.request, url)) + e.respondWith(handleStaticResource(e.request, url, cdnPath)) }) // 处理静态资源请求 - async function handleStaticResource(request, url) { - // 生成CDN子路径 - const hostname = self.location.hostname - const cdnPath = hostname.replace(/\./g, '-') - + async function handleStaticResource(request, url, cdnPath) { const targetUrl = config.cdnUrl + cdnPath + url.pathname + url.search if (config.debug) console.log('PWA-CDN:', url.href, '->', targetUrl)