@wxn0brp/falcon-frame 0.0.8 → 0.0.10

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.
Files changed (2) hide show
  1. package/dist/req.js +12 -3
  2. package/package.json +1 -1
package/dist/req.js CHANGED
@@ -10,9 +10,18 @@ export function handleRequest(req, res, FF) {
10
10
  return originalEnd.call(res, ...any);
11
11
  };
12
12
  const { logger, middlewares } = FF;
13
- const parsedUrl = new URL(req.url || "", "http://localhost");
14
- req.path = parsedUrl.pathname || "/";
15
- req.query = Object.fromEntries(parsedUrl.searchParams);
13
+ try {
14
+ const [path, params] = (req.url || "").split("?");
15
+ const normalizedPath = path.replace(/\/{2,}/g, "/");
16
+ const parsedUrl = new URL(normalizedPath + (params ? `?${params}` : ""), "http://localhost");
17
+ req.path = parsedUrl.pathname || "/";
18
+ req.query = Object.fromEntries(parsedUrl.searchParams);
19
+ }
20
+ catch (e) {
21
+ logger.error(`Error parsing URL (${req.url}): ${e}`);
22
+ res.status(400).end("400: Bad request");
23
+ return;
24
+ }
16
25
  req.cookies = parseCookies(req.headers.cookie || "");
17
26
  req.params = {};
18
27
  req.valid = (schema) => validate(schema, req.body);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/falcon-frame",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "author": "wxn0brP",