diff --git a/worker/src/index.ts b/worker/src/index.ts index 92b74dc888..fe3866f3f5 100644 --- a/worker/src/index.ts +++ b/worker/src/index.ts @@ -151,7 +151,10 @@ export default { return handleError(requestWrapper.error); } env = modifyEnvBasedOnPath(env, requestWrapper.data); - const router = buildRouter(env.WORKER_TYPE); + const router = buildRouter( + env.WORKER_TYPE, + request.url.includes("browser") + ); return router .handle(request, requestWrapper.data, env, ctx) .catch(handleError); diff --git a/worker/src/routers/routerFactory.ts b/worker/src/routers/routerFactory.ts index 003816337d..f58460d0a5 100644 --- a/worker/src/routers/routerFactory.ts +++ b/worker/src/routers/routerFactory.ts @@ -120,7 +120,8 @@ function addBaseRoutes(router: BaseRouter | BaseOpenAPIRouter): void { } export function buildRouter( - provider: Env["WORKER_TYPE"] + provider: Env["WORKER_TYPE"], + includeCors: boolean ): BaseRouter | BaseOpenAPIRouter { if (provider === "HELICONE_API") { const router = OpenAPIRouter< @@ -134,6 +135,18 @@ export function buildRouter( IRequest, [requestWrapper: RequestWrapper, env: Env, ctx: ExecutionContext] >(); + + if (includeCors) { + router.all("*", async (_, __, ___) => { + return new Response(null, { + headers: { + "Access-Control-Allow-Origin": "*", + "Access-Control-Allow-Methods": "*", + "Access-Control-Allow-Headers": "*", + }, + }); + }); + } addBaseRoutes(router); return WORKER_MAP[provider](router); } diff --git a/worker/wrangler.toml b/worker/wrangler.toml index 0009bf34a9..78a6f94082 100644 --- a/worker/wrangler.toml +++ b/worker/wrangler.toml @@ -44,6 +44,7 @@ crons = ["* * * * *", "0 * * * *"] name = "helicone-worker-prod" routes = [ { pattern = "oai.hconeai.com", custom_domain = true, zone_name = "hconeai.com" }, + { pattern = "browser.oai.hconeai.com", custom_domain = true, zone_name = "hconeai.com" }, { pattern = "anthropic.hconeai.com", custom_domain = true, zone_name = "hconeai.com" }, { pattern = "api.hconeai.com", custom_domain = true, zone_name = "hconeai.com" }, { pattern = "openrouter.hconeai.com", custom_domain = true, zone_name = "hconeai.com" }, @@ -83,6 +84,7 @@ DATADOG_ENABLED = "true" name = "helicone-worker-prod-staging" routes = [ { pattern = "oai_staging.hconeai.com", custom_domain = true, zone_name = "hconeai.com" }, + { pattern = "browser.oai_staging.hconeai.com", custom_domain = true, zone_name = "hconeai.com" }, { pattern = "anthropic_staging.hconeai.com", custom_domain = true, zone_name = "hconeai.com" }, { pattern = "api_staging.hconeai.com", custom_domain = true, zone_name = "hconeai.com" }, # openrouter_staging.hconeai.com was failing to deploy