forked from sosvertigo/twintag-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproxy.ts
59 lines (51 loc) · 1.38 KB
/
proxy.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { serve, type ConnInfo } from "https://deno.land/[email protected]/http/server.ts";
const test = async (url:string) => {
try {
const rsp = await fetch(url)
let h = ''
for (const header of rsp.headers) {
h += `${header[0]}: ${header[1]}\n`
}
const text = await rsp.text()
return `${url}\n${rsp.status}\n${h}\n${text.length} body bytes\n${text}`
} catch(err) {
return `${err}`
}
}
async function handler(req: Request, connInfo: ConnInfo): Promise<Response> {
console.log(req, connInfo)
const url = new URL(req.url)
if (url.pathname === '/test') {
const result = await test('https://twintag.io')
console.log(result)
return new Response(result, {
status: 200,
})
}
if (url.pathname === '/admin') {
const result = await test('https://admin.twintag.io')
console.log(result)
return new Response(result, {
status: 200,
})
}
if (url.pathname === '/qid') {
const result = await test('https://sosvertigo-prd.twintag.io/8034d649f75604970f32ef892c759f69')
console.log(result)
return new Response(result, {
status: 200,
})
}
const headers = new Headers()
return new Response(null, {
status: 404,
headers: headers
})
}
serve(handler, {
hostname: '127.0.0.1',
port: 8000,
onListen: ({ port, hostname }) => {
console.log("Listening on", hostname, 'port', port)
}
});