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
import { html } from "jsr:@http/response/html";
import { json } from "jsr:@http/response/json";
import { ok } from "jsr:@http/response/ok";
import { seeOther } from "jsr:@http/response/see-other";
import { byMediaType } from "jsr:@http/route/by-media-type";
import { byMethod } from "jsr:@http/route/by-method";
import { byPattern } from "jsr:@http/route/by-pattern";
import { handle } from "jsr:@http/route/handle";
import { escape } from "jsr:@std/html/entities";
export default handle([
byPattern(
"/:name{.:ext}?",
byMethod({
GET: byMediaType({
"text/html": (req, match) =>
html(`<!DOCTYPE html>\n<h1>Hello ${escape(decodeURIComponent(match.pathname.groups.name))}</h1>`),
"text/plain": (req, match) => ok(`Hello ${decodeURIComponent(match.pathname.groups.name)}`),
"application/json": (req, match) => json({ hello: decodeURIComponent(match.pathname.groups.name) }),
}),
}),
),
() => {
return seeOther("/world");
},
]);