@openhub2/example-cf-nitro-nuxt
v0.0.1
Published
Example: Nuxt + Nitro + Cloudflare with OpenHub remote bindings
Readme
Example: Cloudflare + Nitro + Nuxt
Full-stack example using OpenHub with Cloudflare bindings (D1, KV, R2).
Understanding context
If you're reading me, you probably want to read the sequence:
- openhub monorepo README
- openhub runtime nitro README
- openhub metaframework nuxt README
- openhub provider cloudflare README Then come back to me for the full example details.
Prerequisites
Cloudflare account with:
- D1 database created
- KV namespace created
- R2 bucket created
Update
wrangler.tomlwith your binding IDs
Setup
# From monorepo root
pnpm install
# Or from this directory
pnpm install
# Set up the D1 database schema (if using remote mode)
wrangler d1 execute openhub-examples-test-fixture --remote --file=./migrations/0001_create_users.sqlDevelopment
Local mode (no real bindings)
pnpm devRemote mode (real Cloudflare bindings)
Deploy to Cloudflare Workers first:
pnpm build pnpm deploySet environment variables:
cp .env.example .env # Edit .env with your deployed URL and secretRun with remote bindings:
pnpm dev:remote
API Endpoints
| Endpoint | Method | Binding | Description |
|----------|--------|---------|-------------|
| /api/users | GET | D1 | List users from database |
| /api/users | POST | D1 | Create a new user |
| /api/sessions | GET | KV | Get/create session |
| /api/files | GET | R2 | List uploaded files |
| /api/files | POST | R2 | Upload file |
Project Structure
cf-nitro-nuxt/
├── app.vue # Root component
├── pages/
│ └── index.vue # Home page
├── server/
│ └── api/
│ ├── users.ts # D1 database example
│ ├── session.ts # KV store example
│ └── files.ts # R2 blob example
├── nuxt.config.ts # Nuxt + OpenHub config
├── wrangler.toml # Cloudflare bindings
└── package.jsonHow It Works
@openhub2/metaframework-nuxtregisters the OpenHub module with Nuxt- Module configures
@openhub2/runtime-nitrounder the hood - Runtime registers
@openhub2/provider-cloudflare - In dev mode with
--remote, bindings proxy to your deployed worker - In production, bindings are extracted from Cloudflare's platform context
License
Apache-2.0
