Update deno.ts (#38)

This commit is contained in:
迷渡
2024-01-10 11:22:30 +08:00
committed by GitHub
parent 48fa94e91d
commit 79c00f897a

18
deno.ts
View File

@@ -1,14 +1,14 @@
import { serve } from "https://deno.land/std@0.181.0/http/server.ts";
const OPENAI_API_HOST = "api.openai.com";
serve(async (request) => {
Deno.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);
const newRequest = new Request(url.toString(), {
headers: request.headers,
method: request.method,
body: request.body,
redirect: 'follow'
});
return await fetch(newRequest);
});