This file provides guidance to WARP (warp.dev) when working with code in this repository.
This is a Cloudflare Worker that provides a REST API for interacting with a MySQL database via Cloudflare Hyperdrive. It supports PNP trip and volunteer mapping pages by serving trip data from a MySQL database.
npm run dev # Start local development server on http://localhost:8787/
npm start # Alias for npm run devnpm test # Run tests with Vitestnpm run deploy # Deploy to Cloudflare Workersnpm run cf-typegen # Regenerate worker-configuration.d.ts from wrangler.jsonc bindingsRun this after modifying bindings in wrangler.jsonc to update TypeScript types.
This is a minimal Cloudflare Worker with all logic in src/index.ts. There are no separate route handlers, middleware, or utility modules.
The worker uses Cloudflare Hyperdrive (configured in wrangler.jsonc) to connect to MySQL:
- Binding name:
HYPERDRIVE(accessed viaenv.HYPERDRIVEin the worker) - Local development: Set
WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_HYPERDRIVEenvironment variable for local MySQL connection - Production: Uses Hyperdrive ID
2d8371c752954d879f96d49819ce014e
Database connections are created per-request and closed via ctx.waitUntil(connection.end()).
Currently implements a single endpoint:
- GET /trips: Returns trip data from
prod_forum.vw_linesview with optional filters:last_post_before: Filter trips before datelast_post_after: Filter trips after dateupdated_last_days: Filter trips updated within N days (defaults to 3 if no filters provided)
Query parameters are converted to SQL WHERE clauses with parameterized queries.
Tests use @cloudflare/vitest-pool-workers for Cloudflare Workers environment simulation. The test file imports cloudflare:test module which provides:
env: Mock environment variables/bindingscreateExecutionContext(): Create execution context forctxparameterwaitOnExecutionContext(): Wait forctx.waitUntil()promises before assertionsSELF: Integration-style testing via fetch
Note: Current tests in test/index.spec.ts are boilerplate and don't reflect actual /trips endpoint behavior.
- wrangler.jsonc: Worker configuration including Hyperdrive binding (uses JSONC format with comments)
- tsconfig.json: Main TypeScript config (strict mode enabled, targets ES2021, excludes test directory)
- test/tsconfig.json: Extends main config with experimental Cloudflare Workers types for testing
- worker-configuration.d.ts: Auto-generated from
wrangler.jsoncbindings vianpm run cf-typegen
- mysql2: MySQL client library (requires v3.13.0+ for Cloudflare Workers compatibility)
- wrangler: Cloudflare Workers CLI for dev/deploy
- vitest: Test runner with
@cloudflare/vitest-pool-workersfor Workers-specific testing