-
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathindex.ts
More file actions
58 lines (57 loc) · 1.26 KB
/
Copy pathindex.ts
File metadata and controls
58 lines (57 loc) · 1.26 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
49
50
51
52
53
54
55
56
57
58
import { createRouter, Response, useErrorHandling } from 'fets';
import { z } from 'zod';
export function createTestServerAdapter<TServerContext = {}>(base?: string | undefined) {
return createRouter<TServerContext, {}>({
base,
plugins: [useErrorHandling()],
})
.route({
method: 'GET',
path: '/greetings/:name',
schemas: {
request: {
params: z.object({
name: z.string(),
}),
},
},
handler: req => Response.json({ message: `Hello ${req.params?.name}!` }),
})
.route({
method: 'POST',
path: '/bye',
schemas: {
request: {
json: z.object({
name: z.string(),
}),
},
},
handler: async req => {
const { name } = await req.json();
return Response.json({ message: `Bye ${name}!` });
},
})
.route({
method: 'GET',
path: '/',
handler: () =>
new Response(
`
<html>
<head>
<title>Platform Agnostic Server</title>
</head>
<body>
<p>Hello World!</p>
</body>
</html>
`,
{
headers: {
'Content-Type': 'text/html',
},
},
),
});
}