-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.ts
executable file
·68 lines (59 loc) · 1.58 KB
/
server.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
60
61
62
63
64
65
66
67
68
#!/usr/bin/env -S deno run --unstable --allow-net --allow-env
import { router } from "https://crux.land/router@0.0.12";
import { Client } from "../client.ts";
export function file(
request: Request,
_context,
{ id },
): Promise<Response> {
const client = new Client({
headers: request.headers,
});
const { searchParams } = new URL(request.url);
if (!id) {
id = searchParams.get("id");
}
return client.download(id);
}
function home(request: Request): Response {
const { origin } = new URL(request.url);
const body = `
<!DOCTYPE html>
<html lang="en" class="motion-safe:scroll-smooth text-[18px] antialiased">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fshare</title>
<script src="https://cdn.tailwindcss.com?plugins=forms,typography,aspect-ratio,line-clamp"></script>
</head>
<body class="container mx-auto">
<main class="prose">
<form action="/file" method="GET">
<label>
${origin}/file/<input type="text" name="id" placeholder="file-id" class="p-0 border-0 border-b" />
</label>
<button type="submit">Go</button>
</form>
</main>
</body>
</html>
`;
return new Response(body, {
headers: {
"content-type": "text/html;charset=utf-8",
},
});
}
//#region Server
/**
* Khởi động server và thiết lập router tương đương.
*/
await Deno.serve(router(
{
"GET@/": home,
"GET@/file": file,
"GET@/file/:id": file,
},
));
//#endregion