fix: video generation API routing and worker URL configuration

- Fix itty-router route patterns: :endpoint(*) -> :endpoint+
  The (*) syntax is invalid; :endpoint+ correctly captures multi-segment paths
- Update getWorkerApiUrl() to use VITE_WORKER_ENV for all environments
- Fix dev/staging worker URLs to use jeffemmett-canvas-automerge-dev
- Update wrangler.toml dev environment to use shared D1 database

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Jeff Emmett 2026-01-02 14:21:10 +01:00
parent 7dd03b6f6f
commit e891f8dd33
4 changed files with 24 additions and 16 deletions

View File

@ -11,8 +11,8 @@ const WORKER_ENV = import.meta.env.VITE_WORKER_ENV || 'production' // Default to
const WORKER_URLS = { const WORKER_URLS = {
local: `http://${window.location.hostname}:5172`, local: `http://${window.location.hostname}:5172`,
dev: "https://jeffemmett-canvas-dev.jeffemmett.workers.dev", dev: "https://jeffemmett-canvas-automerge-dev.jeffemmett.workers.dev",
staging: "https://jeffemmett-canvas-dev.jeffemmett.workers.dev", staging: "https://jeffemmett-canvas-automerge-dev.jeffemmett.workers.dev",
production: "https://jeffemmett-canvas.jeffemmett.workers.dev" production: "https://jeffemmett-canvas.jeffemmett.workers.dev"
} }

View File

@ -107,8 +107,11 @@ export function getClientConfig(): ClientConfig {
/** /**
* Get the worker API URL for proxied requests * Get the worker API URL for proxied requests
* In production, this will be the same origin as the app * Uses centralized WORKER_URL configuration based on VITE_WORKER_ENV:
* In development, we need to use the worker's dev port * - local: localhost:5172
* - dev: jeffemmett-canvas-dev.jeffemmett.workers.dev
* - staging: jeffemmett-canvas-dev.jeffemmett.workers.dev
* - production: jeffemmett-canvas.jeffemmett.workers.dev
*/ */
export function getWorkerApiUrl(): string { export function getWorkerApiUrl(): string {
// Check for explicit worker URL override (useful for development) // Check for explicit worker URL override (useful for development)
@ -117,14 +120,18 @@ export function getWorkerApiUrl(): string {
return workerUrl return workerUrl
} }
// In production, use same origin (worker is served from same domain) // Determine worker URL based on VITE_WORKER_ENV
if (typeof window !== 'undefined' && window.location.hostname !== 'localhost') { // This mirrors the logic in src/constants/workerUrl.ts
return '' // Empty string = same origin const workerEnv = import.meta.env.VITE_WORKER_ENV || 'production'
const workerUrls: Record<string, string> = {
local: typeof window !== 'undefined' ? `http://${window.location.hostname}:5172` : 'http://localhost:5172',
dev: 'https://jeffemmett-canvas-automerge-dev.jeffemmett.workers.dev',
staging: 'https://jeffemmett-canvas-automerge-dev.jeffemmett.workers.dev',
production: 'https://jeffemmett-canvas.jeffemmett.workers.dev'
} }
// In development, use the worker dev server return workerUrls[workerEnv] || workerUrls.production
// Default to port 5172 as configured in wrangler.toml
return 'http://localhost:5172'
} }
/** /**

View File

@ -1085,7 +1085,8 @@ const router = AutoRouter<IRequest, [env: Environment, ctx: ExecutionContext]>({
// ============================================================================= // =============================================================================
// Fal.ai proxy - submit job to queue // Fal.ai proxy - submit job to queue
.post("/api/fal/queue/:endpoint(*)", async (req, env) => { // Use :endpoint+ for greedy named wildcard that captures multiple path segments
.post("/api/fal/queue/:endpoint+", async (req, env) => {
if (!env.FAL_API_KEY) { if (!env.FAL_API_KEY) {
return new Response(JSON.stringify({ error: 'FAL_API_KEY not configured' }), { return new Response(JSON.stringify({ error: 'FAL_API_KEY not configured' }), {
status: 500, status: 500,
@ -1131,7 +1132,7 @@ const router = AutoRouter<IRequest, [env: Environment, ctx: ExecutionContext]>({
}) })
// Fal.ai proxy - check job status // Fal.ai proxy - check job status
.get("/api/fal/queue/:endpoint(*)/status/:requestId", async (req, env) => { .get("/api/fal/queue/:endpoint+/status/:requestId", async (req, env) => {
if (!env.FAL_API_KEY) { if (!env.FAL_API_KEY) {
return new Response(JSON.stringify({ error: 'FAL_API_KEY not configured' }), { return new Response(JSON.stringify({ error: 'FAL_API_KEY not configured' }), {
status: 500, status: 500,
@ -1171,7 +1172,7 @@ const router = AutoRouter<IRequest, [env: Environment, ctx: ExecutionContext]>({
}) })
// Fal.ai proxy - get job result // Fal.ai proxy - get job result
.get("/api/fal/queue/:endpoint(*)/result/:requestId", async (req, env) => { .get("/api/fal/queue/:endpoint+/result/:requestId", async (req, env) => {
if (!env.FAL_API_KEY) { if (!env.FAL_API_KEY) {
return new Response(JSON.stringify({ error: 'FAL_API_KEY not configured' }), { return new Response(JSON.stringify({ error: 'FAL_API_KEY not configured' }), {
status: 500, status: 500,
@ -1211,7 +1212,7 @@ const router = AutoRouter<IRequest, [env: Environment, ctx: ExecutionContext]>({
}) })
// Fal.ai subscribe (synchronous generation) - used by LiveImage // Fal.ai subscribe (synchronous generation) - used by LiveImage
.post("/api/fal/subscribe/:endpoint(*)", async (req, env) => { .post("/api/fal/subscribe/:endpoint+", async (req, env) => {
if (!env.FAL_API_KEY) { if (!env.FAL_API_KEY) {
return new Response(JSON.stringify({ error: 'FAL_API_KEY not configured' }), { return new Response(JSON.stringify({ error: 'FAL_API_KEY not configured' }), {
status: 500, status: 500,

View File

@ -98,8 +98,8 @@ bucket_name = 'board-backups-preview'
[[env.dev.d1_databases]] [[env.dev.d1_databases]]
binding = "CRYPTID_DB" binding = "CRYPTID_DB"
database_name = "cryptid-auth-dev" database_name = "cryptid-auth"
database_id = "placeholder-will-be-created-dev" database_id = "35fbe755-0e7c-4b9a-a454-34f945e5f7cc"
[env.dev.triggers] [env.dev.triggers]
crons = ["0 0 * * *"] # Run at midnight UTC every day crons = ["0 0 * * *"] # Run at midnight UTC every day