-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.ts
More file actions
48 lines (44 loc) · 1.08 KB
/
Copy pathproxy.ts
File metadata and controls
48 lines (44 loc) · 1.08 KB
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
import { Application, Router } from "https://deno.land/x/oak/mod.ts";
import { oakCors } from "https://deno.land/x/cors/mod.ts";
import axiod from "https://deno.land/x/axiod/mod.ts";
const app = new Application();
const router = new Router();
router.post("/", async (ctx) => {
const { token, url, params, type } = await ctx.request.body({ type: "json" })
.value;
try {
if (type === "POST") {
ctx.response.body = (
await axiod.post(
url,
{ ...params },
token
? {
headers: {
Cookie: `kkstrauth=${token}`,
},
}
: undefined
)
).data;
} else {
ctx.response.body = (
await axiod.get(
url,
token
? {
headers: {
Cookie: `kkstrauth=${token}`,
},
}
: undefined
)
).data;
}
} catch {
return null;
}
});
app.use(oakCors({ origin: true }));
app.use(router.routes());
await app.listen({ port: 8000 });