Skip to content

Commit

Permalink
added cors for browser. domains
Browse files Browse the repository at this point in the history
  • Loading branch information
chitalian committed May 13, 2024
1 parent 8ff1400 commit d5dda75
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 4 additions & 1 deletion worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 14 additions & 1 deletion worker/src/routers/routerFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand All @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions worker/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d5dda75

Please sign in to comment.