forked from justjavac/openai-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
56 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,26 @@ | ||
//copy this to cloudflare workers | ||
export default { | ||
async fetch(request, env) { | ||
try { | ||
const OPENAI_API_HOST = "api.openai.com"; | ||
const oldUrl = new URL(request.url); | ||
async fetch(request, env) { | ||
try { | ||
const OPENAI_API_HOST = "api.openai.com"; | ||
const oldUrl = new URL(request.url); | ||
|
||
if (oldUrl.pathname === "/") { | ||
return new Response(`https://${oldUrl.hostname}/v1`, { status: 200 }); | ||
} | ||
|
||
if (oldUrl.pathname === "/") { | ||
return new Response(`https://${oldUrl.hostname}/v1`, {status: 200}); | ||
} | ||
const newUrl = new URL(request.url); | ||
newUrl.hostname = OPENAI_API_HOST; | ||
|
||
const newUrl = new URL(request.url); | ||
newUrl.hostname = OPENAI_API_HOST; | ||
const modifiedRequest = new Request(newUrl, { | ||
method: request.method, | ||
headers: request.headers, | ||
body: request.body, | ||
}); | ||
|
||
const modifiedRequest = new Request(newUrl, { | ||
method: request.method, | ||
headers: request.headers, | ||
body: request.body | ||
}); | ||
|
||
return await fetch(modifiedRequest); | ||
} catch (e) { | ||
return new Response(e.stack, {status: 500}); | ||
} | ||
return await fetch(modifiedRequest); | ||
} catch (e) { | ||
return new Response(e.stack, { status: 500 }); | ||
} | ||
} | ||
|
||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { serve } from "https://deno.land/[email protected]/http/server.ts"; | ||
|
||
const OPENAI_API_HOST = "api.openai.com"; | ||
|
||
serve(async (request) => { | ||
const url = new URL(request.url); | ||
|
||
if (url.pathname === "/") { | ||
return fetch(new URL("./Readme.md", import.meta.url)); | ||
} | ||
|
||
url.host = OPENAI_API_HOST; | ||
return await fetch(url, request); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,5 @@ | ||
import { serve } from "https://deno.land/[email protected]/http/server.ts"; | ||
|
||
const OPENAI_API_HOST = "api.openai.com"; | ||
|
||
serve(async (request) => { | ||
const url = new URL(request.url); | ||
|
||
if (url.pathname === "/") { | ||
return fetch(new URL("./Readme.md", import.meta.url)); | ||
} | ||
|
||
url.host = OPENAI_API_HOST; | ||
return await fetch(url, request); | ||
serve(() => { | ||
return fetch(new URL("./Readme.md", import.meta.url)); | ||
}); |