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/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", };