Skip to content

Commit cd6db7a

Browse files
committed
refactor: replace hardcoded custom domain with CUSTOM_DOMAIN env var
- Add CUSTOM_DOMAIN to Env interface (optional) - oauth-metadata.ts / oauth-authorize.ts read from env.CUSTOM_DOMAIN - wrangler.toml: CUSTOM_DOMAIN = https://db-card.sfan-tech.com - Production-portable: set per-environment in wrangler.toml
1 parent 7f09517 commit cd6db7a

4 files changed

Lines changed: 4 additions & 3 deletions

File tree

workers/src/handlers/mcp/oauth-authorize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export async function handleMcpAuthorize(request: Request, env: Env): Promise<Re
5252
// Validate resource — must match this server's URL
5353
const resource = p.get('resource') ?? '';
5454
const allowedOrigins = [env.WORKER_URL];
55-
if (env.ENVIRONMENT === 'staging') allowedOrigins.push('https://db-card.sfan-tech.com');
55+
if (env.CUSTOM_DOMAIN) allowedOrigins.push(env.CUSTOM_DOMAIN);
5656

5757
if (resource) {
5858
// Accept resource as origin or origin+path (e.g. https://host/mcp)

workers/src/handlers/mcp/oauth-metadata.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ const CACHE_CONTROL = 'public, max-age=3600';
66
/** Use the request's origin so metadata URLs match the domain the client connected to */
77
function getBaseUrl(request: Request, env: Env): string {
88
const origin = new URL(request.url).origin;
9-
// Only allow known origins; fall back to WORKER_URL
109
if (origin === env.WORKER_URL) return origin;
11-
if (env.ENVIRONMENT === 'staging' && origin === 'https://db-card.sfan-tech.com') return origin;
10+
if (env.CUSTOM_DOMAIN && origin === env.CUSTOM_DOMAIN) return origin;
1211
return env.WORKER_URL;
1312
}
1413

workers/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface Env {
1717
ORIGIN?: string;
1818
ENVIRONMENT: 'production' | 'staging';
1919
WORKER_URL: string;
20+
CUSTOM_DOMAIN?: string; // e.g. https://db-card.sfan-tech.com
2021
ASSETS: Fetcher;
2122
GOOGLE_CLIENT_ID: string;
2223
GOOGLE_CLIENT_SECRET: string;

workers/wrangler.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ compatibility_date = "2024-04-03" # Enable Durable Objects RPC
77
[vars]
88
ENVIRONMENT = "staging"
99
WORKER_URL = "https://db-card-staging.csw30454.workers.dev"
10+
CUSTOM_DOMAIN = "https://db-card.sfan-tech.com"
1011
GOOGLE_CLIENT_ID = "675226781448-akeqtr5d603ad0bcb3tve5hl4a8c164u.apps.googleusercontent.com"
1112
GEMINI_MODEL = "gemini-3-flash-preview"
1213
GEMINI_LITE_MODEL = "gemini-2.5-flash"

0 commit comments

Comments
 (0)