---
title: "Cloudflare Deployment"
description: "Deploy with Cloudflare D1 for persistent database storage."
canonical_url: "https://nuxtseo.com/docs/ai-ready/guides/cloudflare"
last_updated: "2026-09-25T23:02:52.512Z"
---

Attach a D1 database to keep indexed pages across [Cloudflare](https://cloudflare.com) requests and deployments.
This guide assumes you already have a Nuxt deployment on Workers or Pages.

## Setup

### 1. Create D1 Database

```bash
npx wrangler d1 create ai-ready-db
```

Copy the database ID from the command output:

```text
Created D1 database: ai-ready-db
Database ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
```

### 2. Configure wrangler.toml

Add this binding to your deployment’s Wrangler configuration. Keep its existing entry point and compatibility settings.
If Nitro generates that file, add the binding through `nitro.cloudflare.wrangler.d1_databases` in Nuxt config instead.
Use the same binding name in the module configuration. See [Cloudflare’s D1 binding guide](https://developers.cloudflare.com/d1/get-started/).

```toml [wrangler.toml]
[[d1_databases]]
binding = "AI_READY_DB"
database_name = "ai-ready-db"
database_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
```

### 3. Configure Module

```ts [nuxt.config.ts]
export default defineNuxtConfig({
  aiReady: {
    database: {
      type: 'd1',
      bindingName: 'AI_READY_DB'
    }
  }
})
```

## How It Works

Prerendering prepares `__ai-ready/pages.dump` during the build. An empty runtime database restores that dump into D1.
D1 keeps the data across requests.

On a new build, the module compares content hashes. It adds new pages and marks changed pages for indexing.
Enable runtime sync with poll or cron to process pending pages.
For edits to existing pages between builds, call the [reindex endpoint](/docs/ai-ready/guides/runtime-indexing#control-endpoints-reindex-endpoint-options). There is no automatic page indexing in an `afterResponse` hook.

## NuxtHub

If you use [NuxtHub](https://hub.nuxt.com/docs/database), check the D1 binding created by your installed version.
Set `aiReady.database.bindingName` to that binding. Current NuxtHub database configuration uses `hub.db`.

Nuxt AI Ready does not provision a D1 database itself. Keep the binding configuration in your deployment setup.

## Scheduled Tasks (Cron)

Cloudflare Workers supports native cron triggers, but **Cloudflare Pages does not**.

### Cloudflare Workers

When deploying to Cloudflare Workers with `cron: true`, the module adds cron triggers to Nitro’s generated Wrangler configuration:

```ts [nuxt.config.ts]
export default defineNuxtConfig({
  aiReady: {
    cron: true,
    runtimeSyncSecret: process.env.NUXT_AI_READY_RUNTIME_SYNC_SECRET
  }
})
```

### Cloudflare Pages

Cloudflare Pages cannot run native cron triggers. Set `cron: true` to expose the production HTTP endpoint, then call it externally:

```ts [nuxt.config.ts]
export default defineNuxtConfig({
  aiReady: {
    cron: true,
    runtimeSyncSecret: process.env.NUXT_AI_READY_RUNTIME_SYNC_SECRET
  }
})
```

Then set up an external cron (GitHub Actions, [cron-job.org](http://cron-job.org), etc.):

::code-group
```yaml [GitHub Actions]
name: AI Ready Sync
on:
  schedule:
    - cron: '*/5 * * * *' # every 5 minutes
jobs:
  sync:
    runs-on: ubuntu-latest
    steps:
      - name: Refresh indexed pages
        env:
          SITE_URL: ${{ secrets.SITE_URL }}
          AI_READY_SECRET: ${{ secrets.NUXT_AI_READY_RUNTIME_SYNC_SECRET }}
        run: >
          curl --fail-with-body
          -H "Authorization: Bearer $AI_READY_SECRET"
          "$SITE_URL/__ai-ready/cron"
```

```bash [cURL]
# One-time sync
curl --fail-with-body -H "Authorization: Bearer YOUR_SECRET" -X GET "https://yoursite.pages.dev/__ai-ready/cron"

# Restore the build dump, replacing stored page data
curl --fail-with-body -H "Authorization: Bearer YOUR_SECRET" -X POST "https://yoursite.pages.dev/__ai-ready/restore"
```
::

The production cron endpoint restores the dump when needed, seeds sitemap routes, and indexes pending pages.
The scheduler and deployed app must use the same secret. The cron route is absent during development.

## Notes

- **Build time**: Always uses [SQLite](https://sqlite.org) (D1 not available during build)
- **Local dev**: Query helpers do not expose runtime indexed data. Test a built server or your platform preview.
- **FTS5**: D1 fully supports FTS5 full-text search
- **Pages cron**: Use external scheduler to call `/__ai-ready/cron`

## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
