feature: initial commit
This commit is contained in:
commit
2c27f003c9
15 changed files with 1601 additions and 0 deletions
18
utils/bodyparser.ts
Normal file
18
utils/bodyparser.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
export default async function parse_body(req: Request): Promise<any> {
|
||||
switch (req.headers.get('content-type')) {
|
||||
case 'application/x-www-form-urlencoded': {
|
||||
const form_data = await req.formData();
|
||||
const body: Record<string, any> = {};
|
||||
const keys = form_data.keys();
|
||||
|
||||
for (const key of keys) {
|
||||
body[key] = form_data.get(key);
|
||||
}
|
||||
|
||||
return body;
|
||||
}
|
||||
case 'application/json':
|
||||
default:
|
||||
return req.json();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue