diff --git a/apps/studio/components/interfaces/Workers/Workers.constants.ts b/apps/studio/components/interfaces/Workers/Workers.constants.ts index c76000c4816..8c7df7321d6 100644 --- a/apps/studio/components/interfaces/Workers/Workers.constants.ts +++ b/apps/studio/components/interfaces/Workers/Workers.constants.ts @@ -1,12 +1,21 @@ import type { Worker, WorkerBuildState } from './Workers.types' // Locked to one region at alpha, so nothing in the UI lets you change it. -export const WORKERS_REGION = 'us-west-1' +export const WORKERS_REGION = 'us-west-2' export const WORKERS_REGION_LABEL = 'US West (Oregon)' export const WORKERS_REGION_SHORT = 'US West' -// Private workers share this URL shape; access is enforced by the gateway, not the path. -export const workerGatewayUrl = (name: string) => `https://workers.supabase.co/v1/${name}` +// Workers answer on the project's own domain, alongside /functions/v1, and the api-gateway keeps +// the route dark for projects outside the alpha allow-list. +export const workerUrl = ({ + endpoint, + protocol = 'https', + name, +}: { + endpoint: string | undefined + protocol?: string + name: string +}) => (endpoint ? `${protocol}://${endpoint}/workers/v1/${name}` : undefined) export const LISTENING_PORT = 8080 diff --git a/apps/studio/components/interfaces/Workers/Workers.utils.test.ts b/apps/studio/components/interfaces/Workers/Workers.utils.test.ts index f371d862c73..16342b6a10d 100644 --- a/apps/studio/components/interfaces/Workers/Workers.utils.test.ts +++ b/apps/studio/components/interfaces/Workers/Workers.utils.test.ts @@ -1,5 +1,6 @@ import { describe, expect, it } from 'vitest' +import { workerUrl } from './Workers.constants' import type { Worker } from './Workers.types' import { filterWorkers, @@ -137,3 +138,21 @@ describe('isWorkersAccessDenied', () => { expect(isWorkersAccessDenied(null)).toBe(false) }) }) + +describe('workerUrl', () => { + it('answers on the project domain alongside /functions/v1', () => { + expect(workerUrl({ endpoint: 'abcdefgh.supabase.co', name: 'embed' })).toBe( + 'https://abcdefgh.supabase.co/workers/v1/embed' + ) + }) + + it('honours a non-https protocol', () => { + expect(workerUrl({ endpoint: 'localhost:8000', protocol: 'http', name: 'embed' })).toBe( + 'http://localhost:8000/workers/v1/embed' + ) + }) + + it('has no url until the project settings resolve', () => { + expect(workerUrl({ endpoint: undefined, name: 'embed' })).toBeUndefined() + }) +})