diff --git a/.env.dev b/.env.dev index 0fc68be..215b584 100644 --- a/.env.dev +++ b/.env.dev @@ -1,5 +1,8 @@ API_BASE_URL=https://dev.core-system.sdc.nycu.club/api +# ===== Vite build-time variables (baked into frontend bundle) ===== +VITE_GA_ID=G-TZV3X2G3BH + # ===== Core System Frontend Gateway (Fastify) ===== # Port Fastify listens on inside the container/host diff --git a/.env.stage b/.env.stage new file mode 100644 index 0000000..e6b3183 --- /dev/null +++ b/.env.stage @@ -0,0 +1,21 @@ +API_BASE_URL=https://stage.core-system.sdc.nycu.club/api + +# ===== Vite build-time variables (baked into frontend bundle) ===== +VITE_GA_ID=G-TZV3X2G3BH + +# ===== Core System Frontend Gateway (Fastify) ===== + +# Port Fastify listens on inside the container/host +PORT=80 + +# Upstream Go backend origin for /api proxy and for fetching SEO metadata +BACKEND_ORIGIN=http://172.18.0.1:8080 + +# Optional: override Host header when calling BACKEND_ORIGIN +BACKEND_HOST_HEADER=stage.core-system.sdc.nycu.club + +# Optional: public site origin used for canonical/og:url +PUBLIC_ORIGIN=https://stage.core-system.sdc.nycu.club + +# Optional: cache control for HTML responses +HTML_CACHE_CONTROL=no-store diff --git a/.github/workflows/dev.yaml b/.github/workflows/dev.yaml index 01f769a..08fd57a 100644 --- a/.github/workflows/dev.yaml +++ b/.github/workflows/dev.yaml @@ -110,6 +110,8 @@ jobs: nycusdc/core-system-frontend:dev nycusdc/core-system-frontend:${{ github.sha }} context: . + build-args: | + BUILD_MODE=dev - name: Build and Push Docker image uses: docker/build-push-action@v6 @@ -122,6 +124,8 @@ jobs: nycusdc/core-system-frontend:stage nycusdc/core-system-frontend:${{ github.sha }} context: . + build-args: | + BUILD_MODE=stage Deploy-Dev: if: ${{ contains(github.ref, 'refs/heads/main') }} diff --git a/.github/workflows/snapshot.yaml b/.github/workflows/snapshot.yaml index 79a5fcc..1374fa0 100644 --- a/.github/workflows/snapshot.yaml +++ b/.github/workflows/snapshot.yaml @@ -108,6 +108,8 @@ jobs: nycusdc/core-system-frontend:pr-${{ github.event.number }} nycusdc/core-system-frontend:${{ github.sha }} context: . + build-args: | + BUILD_MODE=dev Deploy: needs: Push-Image diff --git a/Dockerfile b/Dockerfile index 68d7a73..5d66c00 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,14 @@ FROM node:23-alpine AS builder WORKDIR /app +ARG BUILD_MODE=dev + RUN npm i -g pnpm COPY package.json pnpm-lock.yaml ./ RUN pnpm install --frozen-lockfile COPY . . -RUN pnpm run build --mode=dev +RUN pnpm run build --mode=${BUILD_MODE} FROM node:23-alpine WORKDIR /app diff --git a/admin.html b/admin.html index 249d9a4..629ca46 100644 --- a/admin.html +++ b/admin.html @@ -5,7 +5,7 @@ - +
diff --git a/forms.html b/forms.html index 63465e8..86d579f 100644 --- a/forms.html +++ b/forms.html @@ -4,7 +4,7 @@ - + diff --git a/vite.config.ts b/vite.config.ts index d6c8dfb..b094f5e 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -26,6 +26,19 @@ const mpaFallback: Plugin = { export default defineConfig(({ mode }) => { const env = loadEnv(mode, process.cwd(), "VITE_"); + const gaId = env.VITE_GA_ID ?? ""; + + const injectGA: Plugin = { + name: "inject-ga", + transformIndexHtml(html) { + if (!gaId) { + // Remove the GA block entirely when no ID is provided + return html.replace(/