@wxn0brp/falcon-frame 0.9.0 → 0.9.1
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/body-utils.js +13 -9
- package/dist/debug.d.ts +1 -0
- package/dist/debug.js +1 -3
- package/dist/req.js +7 -6
- package/dist/res.js +1 -1
- package/dist/router.js +2 -0
- package/package.json +1 -1
package/dist/body-utils.js
CHANGED
|
@@ -5,10 +5,12 @@ export function parseLimit(limit) {
|
|
|
5
5
|
return limit;
|
|
6
6
|
if (typeof limit !== "string")
|
|
7
7
|
return 0;
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const match = limit
|
|
9
|
+
.toLowerCase()
|
|
10
|
+
.replace(/b$/, "")
|
|
11
|
+
.match(/^(\d+)([kmg])?$/);
|
|
10
12
|
if (!match)
|
|
11
|
-
|
|
13
|
+
throw new Error(`Invalid body limit: ${limit}`);
|
|
12
14
|
const num = parseInt(match[1], 10);
|
|
13
15
|
const unit = match[2]?.toLowerCase();
|
|
14
16
|
switch (unit) {
|
|
@@ -27,19 +29,21 @@ export function getContentType(req) {
|
|
|
27
29
|
}
|
|
28
30
|
export function getRawBody(req, res, limit) {
|
|
29
31
|
return new Promise((resolve, reject) => {
|
|
30
|
-
|
|
32
|
+
const chunks = [];
|
|
33
|
+
let total = 0;
|
|
31
34
|
req.on("data", chunk => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
36
|
+
total += buf.length;
|
|
37
|
+
if (limit && total > limit) {
|
|
35
38
|
res.status(413);
|
|
36
39
|
res.FF._413(req, res);
|
|
37
40
|
req.destroy();
|
|
38
|
-
return reject(
|
|
41
|
+
return reject(new Error("Payload Too Large"));
|
|
39
42
|
}
|
|
43
|
+
chunks.push(buf);
|
|
40
44
|
});
|
|
41
45
|
req.on("end", () => {
|
|
42
|
-
resolve(
|
|
46
|
+
resolve(Buffer.concat(chunks).toString());
|
|
43
47
|
});
|
|
44
48
|
req.on("error", err => {
|
|
45
49
|
reject(err);
|
package/dist/debug.d.ts
CHANGED
package/dist/debug.js
CHANGED
|
@@ -5,7 +5,7 @@ export function createDebug(opts = {}) {
|
|
|
5
5
|
"localhost",
|
|
6
6
|
"127.0.0.1",
|
|
7
7
|
"::1",
|
|
8
|
-
],
|
|
8
|
+
], } = opts;
|
|
9
9
|
if (process.env.NODE_ENV === "production" &&
|
|
10
10
|
!process.env.FF_DEBUG_PRODUCTION_ENABLED)
|
|
11
11
|
return (req, res, next) => {
|
|
@@ -54,7 +54,5 @@ export function createDebug(opts = {}) {
|
|
|
54
54
|
};
|
|
55
55
|
next();
|
|
56
56
|
});
|
|
57
|
-
if (logs)
|
|
58
|
-
router.post("/logs", () => "ok");
|
|
59
57
|
return router;
|
|
60
58
|
}
|
package/dist/req.js
CHANGED
|
@@ -19,17 +19,17 @@ export function handleRequest(req, res, FF, reRoute = false) {
|
|
|
19
19
|
const { logger } = FF;
|
|
20
20
|
try {
|
|
21
21
|
const [path, params] = (req.url || "").split("?");
|
|
22
|
-
const normalizedPath = path.replace(/\/{2,}/g, "/");
|
|
22
|
+
const normalizedPath = decodeURIComponent(path).replace(/\/{2,}/g, "/");
|
|
23
23
|
const parsedUrl = new URL(normalizedPath + (params ? `?${params}` : ""), "http://localhost");
|
|
24
|
-
req.path =
|
|
24
|
+
req.path = parsedUrl.pathname || "/";
|
|
25
25
|
req.query = Object.fromEntries(parsedUrl.searchParams);
|
|
26
|
+
req.cookies = parseCookies(req.headers.cookie || "");
|
|
26
27
|
}
|
|
27
28
|
catch (e) {
|
|
28
|
-
logger.error(`Error parsing
|
|
29
|
+
logger.error(`Error parsing request (${req.url}): ${e}`);
|
|
29
30
|
res.status(400).end("400: Bad request");
|
|
30
31
|
return;
|
|
31
32
|
}
|
|
32
|
-
req.cookies = parseCookies(req.headers.cookie || "");
|
|
33
33
|
req.ip = getIP(req);
|
|
34
34
|
req.params = {};
|
|
35
35
|
req.valid = (schema, regexRules) => validate({
|
|
@@ -152,8 +152,9 @@ export function handleRequest(req, res, FF, reRoute = false) {
|
|
|
152
152
|
next();
|
|
153
153
|
})
|
|
154
154
|
.catch(() => {
|
|
155
|
-
if (!res._ended)
|
|
155
|
+
if (!res._ended) {
|
|
156
156
|
req.body = {};
|
|
157
|
-
|
|
157
|
+
next();
|
|
158
|
+
}
|
|
158
159
|
});
|
|
159
160
|
}
|
package/dist/res.js
CHANGED
|
@@ -54,7 +54,7 @@ export class FFResponse extends http.ServerResponse {
|
|
|
54
54
|
cookie += `; Secure`;
|
|
55
55
|
if (options.sameSite)
|
|
56
56
|
cookie += `; SameSite=${options.sameSite}`;
|
|
57
|
-
this.
|
|
57
|
+
this.appendHeader("Set-Cookie", cookie);
|
|
58
58
|
return this;
|
|
59
59
|
}
|
|
60
60
|
clearCookie(name, options = {}) {
|
package/dist/router.js
CHANGED