-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
page.ts
43 lines (38 loc) · 835 Bytes
/
page.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
import { ConnInfo, Handler } from "./deps.ts";
import { PathArgument, SSR, SSRHandler } from "./types.ts";
interface Page {
pages: Map<string, SSRHandler>;
set: (
path: PathArgument,
ssr: SSR,
handler: Handler,
) => Page;
}
export function page(): Page {
const LOCALHOST = "localhost";
const pages: Map<string, SSRHandler> = new Map();
const instance = {
pages,
set: (
path: PathArgument,
ssr: SSR,
handler: Handler,
) => {
const component = {
path,
ssr,
handler,
};
pages.set(`GET#${LOCALHOST}#${path}`, component);
return instance;
},
};
return instance;
}
export function handleJSXPage(
ssr: SSRHandler,
req: Request,
connInfo: ConnInfo,
): Response | Promise<Response> {
return ssr.handler(req, connInfo);
}