deno / main.ts
samsamsh's picture
Create main.ts
c7acec8 verified
raw
history blame contribute delete
489 Bytes
const targetHost = Deno.env.get("TARGET_HOST") || "generativelanguage.googleapis.com";
// 在Deno.serve配置对象中指定端口
Deno.serve({ port: 7860 }, async (req: Request) => {
const url = new URL(req.url);
url.hostname = targetHost;
url.protocol = "https:";
const headers = new Headers(req.headers);
headers.set('Host', url.hostname);
return await fetch(url.toString(), {
method: req.method,
headers,
body: req.body,
redirect: 'manual',
});
});