Skip to content

Commit 4be849f

Browse files
authored
Merge pull request #36 from PMS61/main
fix: upgrade to Node 20, remove husky, fix Cloudflare
2 parents 002e220 + 686a96a commit 4be849f

23 files changed

Lines changed: 4921 additions & 3656 deletions

.dev.vars.example

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Cloudflare Pages Development Variables
2+
# Copy this file to .dev.vars and fill in your values
3+
# DO NOT commit .dev.vars to git
4+
5+
# Google OAuth
6+
GOOGLE_CLIENT_ID=your_google_client_id_here
7+
GOOGLE_CLIENT_SECRET=your_google_client_secret_here
8+
9+
# NextAuth
10+
NEXTAUTH_SECRET=your_nextauth_secret_here
11+
12+
# Supabase
13+
NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
14+
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_anon_key_here
15+
SUPABASE_SERVICE_ROLE_KEY=your_service_role_key_here
16+
17+
# JWT
18+
JWT_SECRET=your_jwt_secret_here

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ yarn-error.log*
3131
.env.development
3232
.env
3333
.env.example
34+
.dev.vars
3435

3536

3637
# vercel

.husky/commit-msg

Lines changed: 0 additions & 22 deletions
This file was deleted.

.husky/pre-commit

Lines changed: 0 additions & 18 deletions
This file was deleted.

.husky/pre-receive

Lines changed: 0 additions & 17 deletions
This file was deleted.

.node-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
18.18.0
1+
20

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
18.18.0
1+
20

CLOUDFLARE_SETUP.md

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
# Cloudflare Pages Deployment Guide
2+
3+
This guide covers deploying the COC Website to Cloudflare Pages using `@cloudflare/next-on-pages`.
4+
5+
## Prerequisites
6+
7+
- Node.js >= 20.0.0 (check with `node -v`)
8+
- Cloudflare account
9+
- Wrangler CLI installed (`npm install -g wrangler`)
10+
11+
## Quick Start
12+
13+
### 1. Install Dependencies
14+
15+
```bash
16+
npm install
17+
```
18+
19+
### 2. Configure Wrangler
20+
21+
Login to your Cloudflare account:
22+
23+
```bash
24+
npx wrangler login
25+
```
26+
27+
### 3. Add Secrets
28+
29+
All sensitive environment variables must be added as Cloudflare secrets (not in `wrangler.toml`):
30+
31+
```bash
32+
# Google OAuth
33+
npx wrangler secret put GOOGLE_CLIENT_ID
34+
npx wrangler secret put GOOGLE_CLIENT_SECRET
35+
36+
# NextAuth
37+
npx wrangler secret put NEXTAUTH_SECRET
38+
39+
# Supabase
40+
npx wrangler secret put NEXT_PUBLIC_SUPABASE_ANON_KEY
41+
npx wrangler secret put SUPABASE_SERVICE_ROLE_KEY
42+
43+
# JWT
44+
npx wrangler secret put JWT_SECRET
45+
```
46+
47+
You'll be prompted to enter each value interactively.
48+
49+
### 4. Local Development
50+
51+
For local testing with Wrangler:
52+
53+
1. Copy `.dev.vars.example` to `.dev.vars`:
54+
```bash
55+
cp .dev.vars.example .dev.vars
56+
```
57+
58+
2. Fill in your values in `.dev.vars`
59+
60+
3. Run the development server:
61+
```bash
62+
npx wrangler pages dev -- npm run dev
63+
```
64+
65+
### 5. Deploy to Cloudflare Pages
66+
67+
#### Option A: Direct Upload (Recommended for CI/CD)
68+
69+
```bash
70+
npm run build
71+
npx @cloudflare/next-on-pages@1
72+
npx wrangler pages deploy .vercel/output --project-name=coc-website
73+
```
74+
75+
#### Option B: GitHub Integration
76+
77+
1. Go to [Cloudflare Dashboard](https://dash.cloudflare.com)
78+
2. Navigate to **Pages****Create a project**
79+
3. Connect your GitHub repository
80+
4. Configure build settings:
81+
- **Build command**: `npx @cloudflare/next-on-pages@1`
82+
- **Build output directory**: `.vercel/output/static`
83+
- **Root directory**: `/`
84+
5. Add all secrets in **Settings****Environment variables****Production****Add variable**
85+
86+
### 6. Environment Variables in Cloudflare Dashboard
87+
88+
For non-secret variables, add them in the Cloudflare Pages dashboard:
89+
90+
1. Go to your project settings
91+
2. Navigate to **Environment variables**
92+
3. Add:
93+
- `NEXT_OUTPUT_STANDALONE` = `false`
94+
- `NODE_VERSION` = `20`
95+
96+
## Troubleshooting
97+
98+
### Build Fails with "Unsupported engine"
99+
100+
Ensure you're using Node.js >= 20.0.0:
101+
102+
```bash
103+
node -v # Should show v20.x.x or higher
104+
nvm use 20 # If using nvm
105+
```
106+
107+
### Missing Secrets
108+
109+
If you see errors about missing environment variables at runtime:
110+
111+
```bash
112+
# List all secrets
113+
npx wrangler secret list
114+
115+
# Re-add any missing secrets
116+
npx wrangler secret put <SECRET_NAME>
117+
```
118+
119+
### Middleware Issues
120+
121+
The middleware uses Supabase for authentication. Ensure:
122+
- `SUPABASE_SERVICE_ROLE_KEY` is correctly set as a secret
123+
- Your Supabase project is accessible from Cloudflare's edge network
124+
125+
### Worker Size Limit Exceeded
126+
127+
If your build exceeds Cloudflare's worker size limit:
128+
129+
1. Check for large dependencies in your bundle
130+
2. Use dynamic imports for heavy components
131+
3. Consider moving server-heavy logic to API routes
132+
133+
## Project Structure
134+
135+
```
136+
├── .dev.vars.example # Template for local development variables
137+
├── wrangler.toml # Cloudflare Pages configuration
138+
├── next.config.mjs # Next.js config (standalone output disabled for Cloudflare)
139+
└── middleware.ts # Edge middleware for auth protection
140+
```
141+
142+
## Configuration Files
143+
144+
### wrangler.toml
145+
146+
```toml
147+
name = "coc-website"
148+
compatibility_flags = ["nodejs_compat"]
149+
compatibility_date = "2025-01-01"
150+
151+
[build]
152+
command = "npx @cloudflare/next-on-pages@1"
153+
154+
[vars]
155+
NODE_VERSION = "20"
156+
NEXT_OUTPUT_STANDALONE = "false"
157+
```
158+
159+
### next.config.mjs
160+
161+
The `output: 'standalone'` setting is disabled for Cloudflare builds. It's only enabled for Docker deployments via the `NEXT_OUTPUT_STANDALONE` environment variable.
162+
163+
## Useful Commands
164+
165+
```bash
166+
# Check Wrangler version
167+
wrangler --version
168+
169+
# View deployment logs
170+
npx wrangler pages deployment list
171+
172+
# Tail deployment logs
173+
npx wrangler tail
174+
175+
# Open project in browser
176+
npx wrangler pages project open coc-website
177+
```
178+
179+
## Additional Resources
180+
181+
- [Cloudflare Pages Documentation](https://developers.cloudflare.com/pages/)
182+
- [next-on-pages GitHub](https://github.com/cloudflare/next-on-pages)
183+
- [Wrangler CLI Docs](https://developers.cloudflare.com/workers/wrangler/)

Dockerfile

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Stage 1: Dependencies
2-
FROM node:22-alpine AS deps
2+
FROM node:20-alpine AS deps
33
WORKDIR /app
44

55
# Install dependencies needed for build
@@ -12,7 +12,7 @@ COPY package*.json ./
1212
RUN npm ci --ignore-scripts
1313

1414
# Stage 2: Builder
15-
FROM node:22-alpine AS builder
15+
FROM node:20-alpine AS builder
1616
WORKDIR /app
1717

1818
# Copy dependencies from deps stage
@@ -23,12 +23,22 @@ COPY . .
2323
ENV NEXT_TELEMETRY_DISABLED=1
2424
ENV NODE_ENV=production
2525
ENV HUSKY=0
26+
ENV NEXT_OUTPUT_STANDALONE=true
27+
28+
# Required for build-time environment variable validation
29+
# These values are validated at runtime and can be placeholders for build
30+
ENV NEXT_PUBLIC_SUPABASE_URL=https://placeholder.supabase.co
31+
ENV SUPABASE_SERVICE_ROLE_KEY=placeholder_key_for_build_only
32+
ENV GOOGLE_CLIENT_ID=placeholder_for_build
33+
ENV GOOGLE_CLIENT_SECRET=placeholder_for_build
34+
ENV NEXTAUTH_SECRET=placeholder_for_build
35+
ENV JWT_SECRET=placeholder_for_build
2636

2737
# Build application
2838
RUN npm run build
2939

3040
# Stage 3: Production image
31-
FROM node:22-alpine AS runner
41+
FROM node:20-alpine AS runner
3242
WORKDIR /app
3343

3444
# Set environment variables

0 commit comments

Comments
 (0)