Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.dev
Original file line number Diff line number Diff line change
@@ -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
Expand Down
21 changes: 21 additions & 0 deletions .env.stage
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions .github/workflows/dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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') }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/snapshot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- SEO 由 gateway 動態注入 -->
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-TZV3X2G3BH"></script>
<script async src="https://www.googletagmanager.com/gtag/js?id=%VITE_GA_ID%"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag("js", new Date());

gtag("config", "G-TZV3X2G3BH");
gtag("config", "%VITE_GA_ID%");
</script>
</head>
<body style="background-color: #0e0d11">
Expand Down
4 changes: 2 additions & 2 deletions forms.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-TZV3X2G3BH"></script>
<script async src="https://www.googletagmanager.com/gtag/js?id=%VITE_GA_ID%"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag("js", new Date());

gtag("config", "G-TZV3X2G3BH");
gtag("config", "%VITE_GA_ID%");
</script>

<!-- SEO 由 gateway 動態注入 -->
Expand Down
14 changes: 14 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(/<!--\s*Google tag[\s\S]*?<\/script>\s*/g, "");
}
return html.replaceAll("%VITE_GA_ID%", gaId);
}
};

return {
build: {
chunkSizeWarningLimit: 1000,
Expand Down Expand Up @@ -53,6 +66,7 @@ export default defineConfig(({ mode }) => {
plugins: [
react(),
mpaFallback,
injectGA,

visualizer({ open: true, filename: "dist/stats.html", gzipSize: true, brotliSize: true }),

Expand Down
Loading