h3 0.5.2 → 0.5.3
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/dist/index.cjs +20 -2
- package/dist/index.mjs +20 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -21,10 +21,23 @@ function promisifyHandler(handler) {
|
|
|
21
21
|
}
|
|
22
22
|
const promisifyHandle = promisifyHandler;
|
|
23
23
|
function callHandler(handler, req, res) {
|
|
24
|
+
const isMiddleware = handler.length > 2;
|
|
24
25
|
return new Promise((resolve, reject) => {
|
|
25
|
-
const next = (err) =>
|
|
26
|
+
const next = (err) => {
|
|
27
|
+
if (isMiddleware) {
|
|
28
|
+
res.off("close", next);
|
|
29
|
+
res.off("error", next);
|
|
30
|
+
}
|
|
31
|
+
return err ? reject(err) : resolve(void 0);
|
|
32
|
+
};
|
|
26
33
|
try {
|
|
27
|
-
|
|
34
|
+
const returned = handler(req, res, next);
|
|
35
|
+
if (isMiddleware && returned === void 0) {
|
|
36
|
+
res.once("close", next);
|
|
37
|
+
res.once("error", next);
|
|
38
|
+
} else {
|
|
39
|
+
resolve(returned);
|
|
40
|
+
}
|
|
28
41
|
} catch (err) {
|
|
29
42
|
next(err);
|
|
30
43
|
}
|
|
@@ -111,6 +124,7 @@ function createEvent(req, res) {
|
|
|
111
124
|
req.res = res;
|
|
112
125
|
res.event = event;
|
|
113
126
|
res.res = res;
|
|
127
|
+
res.req = res.req || {};
|
|
114
128
|
res.req.res = res;
|
|
115
129
|
res.req.req = req;
|
|
116
130
|
return event;
|
|
@@ -177,6 +191,10 @@ async function useBody(event) {
|
|
|
177
191
|
return event.req[ParsedBodySymbol];
|
|
178
192
|
}
|
|
179
193
|
const body = await useRawBody(event);
|
|
194
|
+
if (event.req.headers["content-type"] === "application/x-www-form-urlencoded") {
|
|
195
|
+
const parsedForm = Object.fromEntries(new URLSearchParams(body));
|
|
196
|
+
return parsedForm;
|
|
197
|
+
}
|
|
180
198
|
const json = destr__default(body);
|
|
181
199
|
event.req[ParsedBodySymbol] = json;
|
|
182
200
|
return json;
|
package/dist/index.mjs
CHANGED
|
@@ -13,10 +13,23 @@ function promisifyHandler(handler) {
|
|
|
13
13
|
}
|
|
14
14
|
const promisifyHandle = promisifyHandler;
|
|
15
15
|
function callHandler(handler, req, res) {
|
|
16
|
+
const isMiddleware = handler.length > 2;
|
|
16
17
|
return new Promise((resolve, reject) => {
|
|
17
|
-
const next = (err) =>
|
|
18
|
+
const next = (err) => {
|
|
19
|
+
if (isMiddleware) {
|
|
20
|
+
res.off("close", next);
|
|
21
|
+
res.off("error", next);
|
|
22
|
+
}
|
|
23
|
+
return err ? reject(err) : resolve(void 0);
|
|
24
|
+
};
|
|
18
25
|
try {
|
|
19
|
-
|
|
26
|
+
const returned = handler(req, res, next);
|
|
27
|
+
if (isMiddleware && returned === void 0) {
|
|
28
|
+
res.once("close", next);
|
|
29
|
+
res.once("error", next);
|
|
30
|
+
} else {
|
|
31
|
+
resolve(returned);
|
|
32
|
+
}
|
|
20
33
|
} catch (err) {
|
|
21
34
|
next(err);
|
|
22
35
|
}
|
|
@@ -103,6 +116,7 @@ function createEvent(req, res) {
|
|
|
103
116
|
req.res = res;
|
|
104
117
|
res.event = event;
|
|
105
118
|
res.res = res;
|
|
119
|
+
res.req = res.req || {};
|
|
106
120
|
res.req.res = res;
|
|
107
121
|
res.req.req = req;
|
|
108
122
|
return event;
|
|
@@ -169,6 +183,10 @@ async function useBody(event) {
|
|
|
169
183
|
return event.req[ParsedBodySymbol];
|
|
170
184
|
}
|
|
171
185
|
const body = await useRawBody(event);
|
|
186
|
+
if (event.req.headers["content-type"] === "application/x-www-form-urlencoded") {
|
|
187
|
+
const parsedForm = Object.fromEntries(new URLSearchParams(body));
|
|
188
|
+
return parsedForm;
|
|
189
|
+
}
|
|
172
190
|
const json = destr(body);
|
|
173
191
|
event.req[ParsedBodySymbol] = json;
|
|
174
192
|
return json;
|