-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlistener.ts
55 lines (50 loc) · 1.55 KB
/
listener.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
// Using dotenv only for local development.
// For deno deploy, using built-in environment variable support.
import "https://deno.land/x/[email protected]/load.ts";
interface Listener {
pattern: URLPattern;
handler: (
{ request, url, pattern }: {
request: Readonly<Request>;
url: Readonly<URL>;
pattern: URLPatternResult;
},
) => Response | Promise<Response>;
}
export const listeners: Listener[] = [
{
pattern: new URLPattern({ pathname: "/" }),
handler: ({ request, url, pattern }) => {
console.log(request, url, pattern.pathname);
return new Response(
'Hello World from <a href="https://github.com/ayame113/deno_deploy_template">ayame113/deno_deploy_template</a> !',
{
headers: {
"Content-Type": "text/html; charset=utf-8",
},
},
);
},
},
/*{
// Process the request when this pattern is matched.
// See also URLPattern API:
// https://developer.mozilla.org/en-US/docs/Web/API/URLPattern
pattern: new URLPattern({ pathname: "/foobar/:id" }),
// Handle the request.
// - request: Request object.
// - url: URL object (requested url).
// should return the Response object.
handler: ({ request, url }) => {
console.log(request, url);
return new Response(
'Hello World from <a href="https://github.com/ayame113/deno_deploy_template">ayame113/deno_deploy_template</a> !',
{
headers: {
"Content-Type": "text/html; charset=utf-8",
},
},
);
},
},*/
];