samsamsh commited on
Commit
c7acec8
·
verified ·
1 Parent(s): c315025

Create main.ts

Browse files
Files changed (1) hide show
  1. main.ts +19 -0
main.ts ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const targetHost = Deno.env.get("TARGET_HOST") || "generativelanguage.googleapis.com";
2
+
3
+ // 在Deno.serve配置对象中指定端口
4
+ Deno.serve({ port: 7860 }, async (req: Request) => {
5
+ const url = new URL(req.url);
6
+
7
+ url.hostname = targetHost;
8
+ url.protocol = "https:";
9
+
10
+ const headers = new Headers(req.headers);
11
+ headers.set('Host', url.hostname);
12
+
13
+ return await fetch(url.toString(), {
14
+ method: req.method,
15
+ headers,
16
+ body: req.body,
17
+ redirect: 'manual',
18
+ });
19
+ });