diff --git a/src/index.ts b/src/index.ts index 8087b850d56cdc4cc1406de2ba86d9f12c818a08..c9599f2e1207a724e0083da37de21d410d992821 100644 --- a/src/index.ts +++ b/src/index.ts @@ -23,10 +23,33 @@ export interface Env { // // Example binding to a Queue. Learn more at https://developers.cloudflare.com/queues/javascript-apis/ // MY_QUEUE: Queue; + ALLOWED_OPENAI_KEYS: string; + HELICONE_KEY: string; } export default { async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> { - return new Response('Hello World!'); + + // The URL you want to proxy the requests to + const url = new URL(request.url); + + // Modify the request to point to the target URL + // For example, if you're proxying to https://example.com + url.hostname = "oai.hconeai.com"; + + // Clone the request to modify it + const modifiedRequest = new Request(url.toString(), request); + + // Add your custom header to the request + modifiedRequest.headers.set("Host", url.hostname); + modifiedRequest.headers.set("Helicone-Auth", "Bearer " + env.HELICONE_KEY); + console.log(modifiedRequest); + + // Make the fetch request with the modified request + const response = await fetch(modifiedRequest); + + // Return the response from the target server + return response; + //return new Response('Hello World!'); }, };