This project demonstrates how to build a Cloudflare Workers-based API using the Hono framework that interfaces with Couchbase's Data API to manage airport data from the travel-sample dataset.
Note: The FTS features require:
- A Full Text Search index with geo-spatial mapping on hotel documents
- The travel-sample dataset with hotel documents in the
inventory.hotelcollection - Hotels must have geo coordinates (
geo.latandgeo.lonfields) for proximity search
- Node.js (v20 or later)
- Wrangler CLI
- Cloudflare account with verified email
- Couchbase Capella cluster with Data API enabled
- Couchbase travel-sample bucket loaded
- Clone the repository
- Navigate to the cloudflare-workers directory:
cd cloudflare-workers- Install dependencies:
npm install- Configure your database (see Database Configuration in the main README)
- Configure your environment variables (see Deployment section for details)
Before using the hotel search functionality, you need to create a Full Text Search index. Use the Node.js script provided in the root of the repository.
See ../scripts/README.md for detailed instructions on creating the required hotel-geo-index for geo-spatial hotel searches.
Start the development server:
npm run dev- Cloudflare account with verified email
- Wrangler CLI installed
wrangler loginSet your Couchbase Data API credentials using one of these methods:
Option 1: Cloudflare Dashboard (Recommended)
- Deploy first:
npm run deploy - Go to Workers Dashboard → Your Worker → Settings → Environment Variables
- Add:
DATA_API_USERNAME,DATA_API_PASSWORD,DATA_API_ENDPOINTas secrets
Option 2: CLI Secrets
wrangler secret put DATA_API_USERNAME
wrangler secret put DATA_API_PASSWORD
wrangler secret put DATA_API_ENDPOINTOption 3: wrangler.jsonc (Development only)
{
"vars": {
"DATA_API_USERNAME": "your_username",
"DATA_API_PASSWORD": "your_password",
"DATA_API_ENDPOINT": "your_endpoint"
}
}npm run deployThis project includes comprehensive unit tests for all handler functions using Vitest and the @cloudflare/vitest-pool-workers testing framework.
Run all unit tests:
npm run testRun specific test categories:
# Run only unit tests
npm run test:unit
# Run only handler tests
npm run test:handlers
# Run a specific test file
npm test test/handlers/getHotelsNearAirport.spec.tsIntegration tests are available to test against your deployed Worker. These tests perform real API calls to your deployed Cloudflare Worker endpoint.
Run integration tests:
#Set environment variable and run
export WORKER_URL="https://your-worker.your-subdomain.workers.dev"
npm run test:integrationsrc/
├── handlers/ # API route handlers
│ ├── createAirport.ts
│ ├── getAirport.ts
│ ├── updateAirport.ts
│ ├── deleteAirport.ts
│ ├── getAirportRoutes.ts
│ ├── getAirportAirlines.ts
│ └── getHotelsNearAirport.ts
├── types/ # TypeScript type definitions
│ └── env.ts
├── utils/ # Utility functions
└── index.ts # Main application entry point
test/
├── handlers/ # Handler unit tests
│ ├── createAirport.spec.ts
│ ├── getAirport.spec.ts
│ ├── updateAirport.spec.ts
│ ├── deleteAirport.spec.ts
│ ├── getAirportRoutes.spec.ts
│ ├── getAirportAirlines.spec.ts
│ └── getHotelsNearAirport.spec.ts
├── utils/ # Test utilities and helpers
│ └── testHelpers.ts
├── integration.test.ts # Integration tests for deployed Worker
└── setup.ts # Test setup configuration