-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
39 lines (32 loc) · 875 Bytes
/
main.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
import {
decode,
Application,
Router,
} from "./deps.ts";
const router = new Router();
router.get("/decode/:url*", async (ctx) => {
const url = new TextDecoder().decode(decode(ctx.params.url ?? ""));
console.log('u', url);
let resp = await fetch(url, {
redirect: "manual",
});
const cookie = resp.headers.get("set-cookie");
resp = await fetch(url, {
headers: {
"Cookie": cookie?.split(";")[0] ?? "",
},
});
ctx.response.body = await resp.text()
});
const app = new Application();
app.use(async (ctx, next) => {
console.log(`${ctx.request.method} ${ctx.request.url}`);
await next();
});
app.use(router.routes());
app.use(router.allowedMethods());
app.addEventListener(
"listen",
(e) => console.log("Listening on http://localhost:8080"),
);
await app.listen({ port: 8080 });