This guide details how to deploy the myimageupscaler.com application to Cloudflare Pages using the @cloudflare/next-on-pages adapter.
- Cloudflare Account: You need an active account.
- Wrangler CLI: Installed via
npm install -g wrangler(or used vianpx). - Project Setup: Ensure you have run
yarn installand the project is configured as per the PRD.
Before deploying, verify the build locally to ensure the Cloudflare adapter works correctly.
Run the pages build script to generate the worker and static assets.
yarn pages:buildSuccess: This should create a .vercel/output directory.
Run the local Cloudflare emulation.
yarn pages:previewSuccess: The app should be accessible at http://localhost:8788.
Verify: Visit http://localhost:8788/api/health to check the worker status.
Use Wrangler to upload the built assets directly from your machine.
-
Login (if not already logged in):
npx wrangler login
-
Deploy:
yarn deploy
Note: This runs
pages:buildand thenwrangler pages deploy. -
Verify: Wrangler will output a URL (e.g.,
https://myimageupscaler.com.pages.dev).
Connect your GitHub repository to Cloudflare Pages for automatic deployments.
- Push Code: Ensure your changes (including
wrangler.tomlandpackage.jsonupdates) are pushed to GitHub. - Cloudflare Dashboard:
- Go to Workers & Pages > Create Application > Pages > Connect to Git.
- Select the
myimageupscaler.comrepository.
- Build Settings:
- Framework Preset:
Next.js - Build Command:
npx @cloudflare/next-on-pages(oryarn pages:build) - Build Output Directory:
.vercel/output/static - Node.js Compatibility: Ensure the
nodejs_compatflag is set in Settings > Functions > Compatibility Flags, OR ensurewrangler.tomlis present in the root.
- Framework Preset:
You must configure the following environment variables in Cloudflare Pages Dashboard before deployment:
Navigate to Settings > Environment Variables in your Cloudflare Pages project and add:
NEXT_PUBLIC_BASE_URL=https://myimageupscaler.com
NEXT_PUBLIC_SUPABASE_URL=your_supabase_project_url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
NEXT_PUBLIC_AMPLITUDE_API_KEY=your_amplitude_api_key
NEXT_PUBLIC_GA_MEASUREMENT_ID=your_ga4_measurement_id
NEXT_PUBLIC_BASELIME_KEY=your_baselime_public_keySUPABASE_SERVICE_ROLE_KEY=your_supabase_service_role_key
STRIPE_SECRET_KEY=your_stripe_secret_key
STRIPE_WEBHOOK_SECRET=your_stripe_webhook_secret
GEMINI_API_KEY=your_gemini_api_key
BASELIME_API_KEY=your_baselime_server_api_keyNEXT_PUBLIC_STRIPE_STARTER_CREDITS_PRICE_ID=price_xxx
NEXT_PUBLIC_STRIPE_PRO_CREDITS_PRICE_ID=price_xxx
NEXT_PUBLIC_STRIPE_ENTERPRISE_CREDITS_PRICE_ID=price_xxx
NEXT_PUBLIC_STRIPE_HOBBY_MONTHLY_PRICE_ID=price_xxx
NEXT_PUBLIC_STRIPE_PRO_MONTHLY_PRICE_ID=price_xxx
NEXT_PUBLIC_STRIPE_BUSINESS_MONTHLY_PRICE_ID=price_xxx- Never commit
.envor.env.prodfiles to version control - Set variables for both Production and Preview environments
- After adding variables, trigger a new deployment for changes to take effect
- Use the
.env.exampleand.env.prod.examplefiles as reference
- Go to Custom domains in your Cloudflare Pages project
- Click Set up a custom domain
- Enter
myimageupscaler.com - Click Continue
If your domain is already on Cloudflare:
- DNS records will be automatically configured
- SSL certificate will be automatically provisioned
If your domain is external:
- Add a CNAME record pointing to your
*.pages.devURL - Wait for DNS propagation (up to 48 hours)
- Go to SSL/TLS in Cloudflare Dashboard
- Set encryption mode to Full (strict)
- Enable Always Use HTTPS
- Enable Automatic HTTPS Rewrites
- Visit
https://myimageupscaler.com - Check SSL certificate (should show valid certificate)
- Test all critical routes:
/- Landing page/upscaler- Upscaler page/pricing- Pricing page/help- Help page/api/health- Health check
- Application loads successfully
- SSL certificate is valid
- All environment variables are accessible
- Database connections work (Supabase)
- Payment processing works (Stripe)
- Image processing works (Gemini API)
- Analytics tracking works (Amplitude + GA4)
- Error monitoring works (Baselime)
- Health check endpoint returns 200:
/api/health - Sitemap accessible:
/sitemap.xml - Robots.txt accessible:
/robots.txt
| Issue | Solution |
|---|---|
| Build fails on "Image Optimization" | Next.js Image Optimization is not supported on Pages by default. Use unoptimized: true in next.config.js or use Cloudflare Images. |
| "Edge Runtime" errors | Ensure export const runtime = 'edge' is set in your API routes if they use Edge-specific APIs, though next-on-pages usually handles standard Node.js APIs via the compat flag. |
| Environment Variables not loading | Ensure variables are set for the correct environment (Production/Preview). Trigger a new deployment after adding variables. |
| API routes failing | Check that all server-side secrets are configured. Review function logs in Cloudflare Dashboard. |
| Database connection errors | Verify SUPABASE_SERVICE_ROLE_KEY is set correctly. Check Supabase project URL matches. |
| Stripe webhooks failing | Update webhook endpoint in Stripe Dashboard to https://myimageupscaler.com/api/webhooks/stripe. Verify webhook secret matches. |