From 8cb56142cd72fe2d0612307c5348b8758f12fd18 Mon Sep 17 00:00:00 2001 From: Bas van den Aakster Date: Sat, 8 Nov 2025 11:45:41 +0100 Subject: [PATCH] Fix Cloudflare Worker compatibility for version endpoint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add version parameter to AppConfig interface - Pass version from environment config instead of using process.env - Update worker.ts to pass VERSION environment variable - Update wrangler.toml with VERSION variable - Update deploy script to automatically set VERSION to git commit hash This fixes the 'process is not defined' error in Cloudflare Workers 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- package.json | 2 +- src/app.ts | 3 ++- src/index.ts | 1 + src/worker.ts | 2 ++ wrangler.toml | 1 + 5 files changed, 7 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 48aeaba..4828cc3 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "dev": "ts-node src/index.ts", "start": "node dist/index.js", "test": "echo \"Error: no test specified\" && exit 1", - "deploy": "npx wrangler deploy src/worker.ts" + "deploy": "npx wrangler deploy src/worker.ts --var VERSION:$(git rev-parse --short HEAD)" }, "devDependencies": { "@cloudflare/workers-types": "^4.20251014.0", diff --git a/src/app.ts b/src/app.ts index 03c7ca3..6b585f5 100644 --- a/src/app.ts +++ b/src/app.ts @@ -6,6 +6,7 @@ import type { Context } from 'hono'; export interface AppConfig { sessionTimeout: number; corsOrigins: string[]; + version?: string; } /** @@ -54,7 +55,7 @@ export function createApp(storage: Storage, config: AppConfig) { */ app.get('/', (c) => { return c.json({ - version: process.env.RONDEVU_VERSION || 'unknown' + version: config.version || 'unknown' }); }); diff --git a/src/index.ts b/src/index.ts index 4fd9f4c..15b9d11 100644 --- a/src/index.ts +++ b/src/index.ts @@ -31,6 +31,7 @@ async function main() { const app = createApp(storage, { sessionTimeout: config.sessionTimeout, corsOrigins: config.corsOrigins, + version: process.env.RONDEVU_VERSION || 'unknown', }); const server = serve({ diff --git a/src/worker.ts b/src/worker.ts index f143237..5a86c26 100644 --- a/src/worker.ts +++ b/src/worker.ts @@ -8,6 +8,7 @@ export interface Env { DB: D1Database; SESSION_TIMEOUT?: string; CORS_ORIGINS?: string; + VERSION?: string; } /** @@ -31,6 +32,7 @@ export default { const app = createApp(storage, { sessionTimeout, corsOrigins, + version: env.VERSION || 'unknown', }); // Handle request diff --git a/wrangler.toml b/wrangler.toml index d8acc43..67acaab 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -12,6 +12,7 @@ database_id = "b94e3f71-816d-455b-a89d-927fa49532d0" [vars] SESSION_TIMEOUT = "300000" # 5 minutes in milliseconds CORS_ORIGINS = "*" # Comma-separated list of allowed origins +VERSION = "unknown" # Set to git commit hash before deploying # Build configuration [build]