@joinremba/gate 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/validate.ts CHANGED
@@ -63,7 +63,7 @@ export function validateRequest(
63
63
  }
64
64
 
65
65
  export function validate(schemas: ValidationSchemas) {
66
- return (req: Request) => {
66
+ return async (req: Request) => {
67
67
  const url = new URL(req.url);
68
68
 
69
69
  const searchParams: Record<string, string> = {};
@@ -71,8 +71,15 @@ export function validate(schemas: ValidationSchemas) {
71
71
  searchParams[k] = v;
72
72
  });
73
73
 
74
+ let body: unknown;
75
+ try {
76
+ body = await req.json();
77
+ } catch {
78
+ body = undefined;
79
+ }
80
+
74
81
  const result = validateRequest(schemas, {
75
- body: req.body,
82
+ body,
76
83
  query: searchParams,
77
84
  headers: Object.fromEntries(req.headers.entries()),
78
85
  });