From 41cdb815c212da483f141c7b48e40591dea556bb Mon Sep 17 00:00:00 2001 From: Max Kokorin Date: Thu, 22 Oct 2026 17:10:04 +0600 Subject: [PATCH 1/2] Deploy static frontend to GitHub Pages Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/ci.yml | 43 ++++++++++++++++++++++++++++ .gitignore | 1 + README.md | 10 +++++++ frontend/next.config.mjs | 8 +++++- frontend/src/app/api/events/route.ts | 2 ++ frontend/src/lib/constants.ts | 5 ++-- 6 files changed, 66 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5775251..af7aba2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -134,6 +134,49 @@ jobs: docker compose --project-name githubble --env-file .env -f docker-compose.yaml ps REMOTE + pages-build: + name: Build GitHub Pages + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + needs: [go, go-lint, frontend, docker] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - uses: actions/setup-node@v7 + with: + node-version: '22' + cache: npm + cache-dependency-path: frontend/package-lock.json + - uses: actions/configure-pages@v5 + - name: Build static export + working-directory: frontend + env: + GITHUB_PAGES: 'true' + PAGES_BASE_PATH: /${{ github.event.repository.name }} + NEXT_PUBLIC_SSE_URL: ${{ vars.PAGES_SSE_URL || 'https://githubble.root.sx/api/events' }} + NEXT_TELEMETRY_DISABLED: '1' + run: | + npm ci + # Route handlers cannot be exported statically; the stream comes from the public deployment. + rm -rf src/app/api + npm run build + - uses: actions/upload-pages-artifact@v4 + with: + path: frontend/out + + pages-deploy: + name: Deploy to GitHub Pages + needs: pages-build + runs-on: ubuntu-latest + permissions: + pages: write + id-token: write + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + steps: + - id: deployment + uses: actions/deploy-pages@v4 + notify: name: Notify Telegram if: always() && !cancelled() && github.event_name == 'push' && github.ref == 'refs/heads/master' diff --git a/.gitignore b/.gitignore index 28d4efb..ddd5503 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,7 @@ dist # Dependency directory node_modules .next +out *.tsbuildinfo # Optional npm cache directory diff --git a/README.md b/README.md index b8f29a6..637f0ca 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,16 @@ in `.env` for additional diagnostics (`info` is the default), then run new stars/forks, GitHub poll interval, rate-limit status and errors; they do not include token values or event payloads. +## GitHub Pages + +On every push to `master` CI also publishes a static build of the frontend to +GitHub Pages (enable it once in Settings → Pages → Source: GitHub Actions). +The static build has no Next.js route, so it reads the SSE stream from +`https://githubble.root.sx/api/events`; override it with the repository +variable `PAGES_SSE_URL`. Local check: +`GITHUB_PAGES=true PAGES_BASE_PATH=/githubble NEXT_PUBLIC_SSE_URL=... npm run build` +after temporarily removing `frontend/src/app/api`. + ## Checks ```sh diff --git a/frontend/next.config.mjs b/frontend/next.config.mjs index 01761fd..c3e9f36 100644 --- a/frontend/next.config.mjs +++ b/frontend/next.config.mjs @@ -1,7 +1,13 @@ +// GitHub Pages build: a static export with no API route (the workflow removes +// src/app/api) that streams from the public deployment via NEXT_PUBLIC_SSE_URL. +const pages = process.env.GITHUB_PAGES === "true"; + /** @type {import('next').NextConfig} */ const nextConfig = { reactStrictMode: true, - output: "standalone", + output: pages ? "export" : "standalone", + basePath: pages ? process.env.PAGES_BASE_PATH || "" : "", + images: pages ? { unoptimized: true } : undefined, }; export default nextConfig; diff --git a/frontend/src/app/api/events/route.ts b/frontend/src/app/api/events/route.ts index e7b160f..52ad3a5 100644 --- a/frontend/src/app/api/events/route.ts +++ b/frontend/src/app/api/events/route.ts @@ -18,6 +18,8 @@ export async function GET(request: Request) { "Content-Type": "text/event-stream", "Cache-Control": "no-cache, no-transform", "X-Accel-Buffering": "no", + // The stream is public; allow the GitHub Pages build to read it. + "Access-Control-Allow-Origin": "*", }, }); } catch { diff --git a/frontend/src/lib/constants.ts b/frontend/src/lib/constants.ts index 53e94b4..b5d46b5 100644 --- a/frontend/src/lib/constants.ts +++ b/frontend/src/lib/constants.ts @@ -1,6 +1,7 @@ // Stream via the same-origin Next.js route: the browser never needs to know -// the backend's internal Docker hostname or a public backend port. +// the backend's internal Docker hostname or a public backend port. The static +// GitHub Pages build overrides it with the public deployment's stream URL. export const CONFIG = { numEventsOnPageValues: [15, 30, 50, 70, 90, 110], - sseUrl: "/api/events", + sseUrl: process.env.NEXT_PUBLIC_SSE_URL || "/api/events", }; From ea170e39a707dd43882aa4c8db9a9914bf2c9702 Mon Sep 17 00:00:00 2001 From: Max Kokorin Date: Thu, 22 Oct 2026 17:12:33 +0600 Subject: [PATCH 2/2] Revert README changes Co-Authored-By: Claude Sonnet 5.5 --- README.md | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/README.md b/README.md index 637f0ca..b8f29a6 100644 --- a/README.md +++ b/README.md @@ -57,16 +57,6 @@ in `.env` for additional diagnostics (`info` is the default), then run new stars/forks, GitHub poll interval, rate-limit status and errors; they do not include token values or event payloads. -## GitHub Pages - -On every push to `master` CI also publishes a static build of the frontend to -GitHub Pages (enable it once in Settings → Pages → Source: GitHub Actions). -The static build has no Next.js route, so it reads the SSE stream from -`https://githubble.root.sx/api/events`; override it with the repository -variable `PAGES_SSE_URL`. Local check: -`GITHUB_PAGES=true PAGES_BASE_PATH=/githubble NEXT_PUBLIC_SSE_URL=... npm run build` -after temporarily removing `frontend/src/app/api`. - ## Checks ```sh