Configure these in your Cloudflare Pages dashboard (Settings > Builds & deployments):
- Framework preset: None
- Build command:
npm run build - Build output directory:
public - Root directory:
/(or leave blank)
Add under Settings > Environment variables > Production:
| Variable | Value |
|---|---|
HUGO_VERSION |
0.139.3 |
NODE_VERSION |
18 |
npm install- Installs dependencies (Hono, Zod, TypeScript, etc.)npm run buildexecutes:npm run build:data→ Runsscripts/build-api-data.js→ Generatesfunctions/regions.jsonnpm run build:worker→ Compiles TypeScript tofunctions/_worker.js(Hono app)hugo --gc --minify→ Generates static site inpublic/
- Cloudflare Pages deploys:
- Static files from
public/(the Hugo site) - Functions from
functions/(the Hono API worker)
- Static files from
public/ # Hugo static site
├── index.html
├── llms.txt
├── llms-full.txt
└── ...
functions/ # Cloudflare Pages Functions
├── regions.json # Generated region data (loaded by worker)
├── _worker.js # Compiled Hono application (all API routes)
└── [[path]].js # Catch-all route handler
src/functions/ # TypeScript source (not deployed)
├── _worker.ts # Main Hono app
├── routes/ # API route handlers
├── schemas/ # Zod schemas with OpenAPI metadata
├── types/ # TypeScript type definitions
└── utils/ # Helper functions
Once deployed, these endpoints should work:
GET /api/v1/health- Health checkGET /api/v1/ping- Connectivity testGET /api/v1/regions- List all regionsGET /api/v1/regions/{id}- Get specific regionGET /api/v1/services- List servicesGET /api/docs- Scalar API Reference (interactive docs)GET /api/openapi.json- OpenAPI specification
Symptom: Accessing /api/v1/regions returns the Hugo site HTML
Causes:
- Build command not set to
npm run build - Functions directory not included in deployment
functions/regions.jsonnot generated during build
Solution:
- Check build logs in Cloudflare Pages dashboard
- Verify
npm run build:dataexecutes successfully - Confirm both
public/andfunctions/exist after build - Re-deploy the site
Check:
- Node.js version is 18 or higher
- Hugo version is set correctly
- All dependencies install successfully
data/regions/*.yamlfiles exist
Verify:
functions/directory exists at root level (not insidepublic/)- Function files have correct exports (
export async function onRequestGet) regions.jsonexists infunctions/after build
Before deploying, test locally:
# Build the data and site
npm run build
# Verify functions directory
ls -la functions/
# Test with Wrangler (optional)
npm run devAfter configuring the build settings:
- Trigger a new deployment (Settings > Builds & deployments > Retry deployment)
- Check build logs for any errors
- Verify
/api/v1/healthreturns JSON (not HTML) - Test other API endpoints
- Check
/api/docsfor Scalar API Reference UI - Verify
/api/openapi.jsongenerates valid OpenAPI spec