-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.ts
More file actions
41 lines (35 loc) · 788 Bytes
/
app.ts
File metadata and controls
41 lines (35 loc) · 788 Bytes
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
import { Hono } from "hono";
const app = new Hono();
app.all("*", async (c) => {
const headers: Record<string, string> = {};
c.req.raw.headers.forEach((value, key) => {
headers[key] = value;
});
let body = null;
try {
switch (c.req.header("content-type")?.split(";")[0].trim()) {
case "application/json":
body = await c.req.json();
break;
case "application/x-www-form-urlencoded":
body = await c.req.parseBody();
break;
default:
body = await c.req.text();
}
} catch {
body = await c.req.text();
}
return c.json(
{
method: c.req.method,
url: c.req.url,
path: c.req.path,
query: c.req.query(),
headers,
body,
},
200,
);
});
export default app;