-
Notifications
You must be signed in to change notification settings - Fork 108
d1-http driver points wrong API URL #793
Description
Describe the bug
The d1-http driver in @nuxthub/core uses an incorrect Cloudflare D1 API endpoint URI, causing all database queries to fail with 405 errors. The endpoint path should be /d1/database/ but the code uses /d1/db/.
[2:15:47 PM] ERROR D1 HTTP Error: https://api.cloudflare.com/client/v4/accounts/<my account id>/d1/db/<my database id>/raw {"sql":"CREATE TABLE IF NOT EXISTS _hub_migrations (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n name TEXT UNIQUE,\n applied_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL\n);","params":[]} 405 { success: false,
errors:
[ { code: 10000,
message: 'POST method not allowed for the api_token authentication scheme' } ] }
[nuxt:hub] ERROR Failed to create migrations table 2:15:47 PM
[POST] "https://api.cloudflare.com/client/v4/accounts/<my account id>/d1/db/<my database id>/raw": 405 Not Allowed
Steps to reproduce
- Configure
@nuxthub/coreto use the d1-http driver:export default defineNuxtConfig({ hub: { db: { dialect: 'sqlite', driver: 'd1-http', } } })
- Add config to
.env- NUXT_HUB_CLOUDFLARE_ACCOUNT_ID
- NUXT_HUB_CLOUDFLARE_API_TOKEN
- NUXT_HUB_CLOUDFLARE_DATABASE_ID
- Run
nuxt dev - Show error during db migrate process
Expected behavior
Database queries should successfully execute using the correct Cloudflare D1 API endpoint as documented in the Cloudflare D1 API documentation:
POST /client/v4/accounts/{account_id}/d1/database/{database_id}/raw
Actual behavior
The driver attempts to call an incorrect endpoint:
POST /client/v4/accounts/{account_id}/d1/db/{database_id}/raw
This results in 405 errors because the path segment should be /database/ not /db/.
Root cause
In src/db/setup.ts, the d1-http driver configuration uses an incorrect API endpoint:
Fix
Change d1/db/ to d1/database/ to match the official Cloudflare D1 API specification:
Reference
Cloudflare D1 API Documentation: https://developers.cloudflare.com/api/resources/d1/subresources/database/methods/raw/
Environment
@nuxthub/core: 0.10.4, 0.10.5 (and likely earlier versions)
Affected driver: d1-http