# Deploy Yaltopia FIFA to Cloudflare This app uses [**OpenNext**](https://opennext.js.org/cloudflare) (`@opennextjs/cloudflare`) to run Next.js 15 on **Cloudflare Workers** (not legacy `next-on-pages`). ## Prerequisites 1. [Cloudflare account](https://dash.cloudflare.com/sign-up) 2. Node.js 20+ 3. Wrangler logged in: `npx wrangler login` ## 1. Install dependencies ```bash npm install ``` ## 2. Environment variables (build + runtime) `NEXT_PUBLIC_*` values are embedded at **build time**. Before `npm run deploy`, ensure they are set: **Option A — local deploy (use your `.env.local`):** ```bash # .env.local must exist with: # NEXT_PUBLIC_SUPABASE_URL=https://xxxx.supabase.co # NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJ... or sb_publishable_... npm run deploy ``` **Option B — Cloudflare Dashboard (Git CI):** Workers & Pages → your project → **Settings** → **Variables and secrets**: | Name | Type | Notes | |------|------|--------| | `NEXT_PUBLIC_SUPABASE_URL` | Plaintext | Build + production | | `NEXT_PUBLIC_SUPABASE_ANON_KEY` | Plaintext | Build + production | Mark both as available at **build** time if the UI offers it. ## 3. Supabase Auth redirect URLs In Supabase → **Authentication** → **URL configuration**, add your Cloudflare URLs: ``` https://yaltopia-fifa..workers.dev/auth/callback https://yaltopia-fifa..workers.dev/reset-password https://your-custom-domain.com/auth/callback https://your-custom-domain.com/reset-password ``` Set **Site URL** to your production URL (e.g. `https://yaltopia-fifa.your-account.workers.dev`). ## 4. Deploy from CLI ```bash npm run deploy ``` First run creates the Worker `yaltopia-fifa` and prints a `*.workers.dev` URL. ## 5. Preview locally (Workers runtime) ```bash cp .dev.vars.example .dev.vars npm run preview ``` Opens on `http://localhost:8787` (approx.) — closer to production than `next dev`. ## 6. Custom domain 1. Cloudflare Dashboard → **Workers & Pages** → **yaltopia-fifa** 2. **Settings** → **Domains & routes** → **Add custom domain** 3. Update Supabase redirect URLs to use that domain ## 7. GitHub / GitLab CI (optional) Connect the repo in Cloudflare: 1. **Workers & Pages** → **Create** → **Workers** → **Connect to Git** 2. Build command: `npm run deploy` or split: - Build: `npx opennextjs-cloudflare build` - Deploy: `npx opennextjs-cloudflare deploy` 3. Add the same `NEXT_PUBLIC_*` variables in project settings ## Scripts | Script | Purpose | |--------|---------| | `npm run dev` | Next.js dev server (Node) | | `npm run preview` | Build + local Workers preview | | `npm run deploy` | Build + deploy to Cloudflare | | `npm run upload` | Build + upload version only | ## Troubleshooting - **Build fails on env**: Set `NEXT_PUBLIC_SUPABASE_URL` and `NEXT_PUBLIC_SUPABASE_ANON_KEY` before build. - **Auth redirect error**: Add exact callback URLs in Supabase (include `/auth/callback`). - **Images**: Team logos use `next/image` + Supabase storage; `wrangler.jsonc` enables the `IMAGES` binding. - **League Master URLs**: Still `/login/master`, `/master`, etc. — not linked on the public home page. ## Project files - `wrangler.jsonc` — Worker name, compatibility, assets - `open-next.config.ts` — OpenNext Cloudflare adapter - `public/_headers` — static asset caching