@middy/http-router
Advanced tools
Comparing version 5.0.2 to 5.0.3
17
index.js
@@ -8,3 +8,2 @@ import { createError } from '@middy/util'; | ||
let { method, path, handler } = route; | ||
// Prevents `routesType[method][path] = handler` from flagging: This assignment may alter Object.prototype if a malicious '__proto__' string is injected from library input. | ||
if (!enumMethods.includes(method)) { | ||
@@ -17,7 +16,5 @@ throw new Error('Method not allowed', { | ||
} | ||
// remove trailing slash, but not if it's the first one | ||
if (path.endsWith('/') && path !== '/') { | ||
path = path.substr(0, path.length - 1); | ||
} | ||
// Static | ||
if (path.indexOf('{') < 0) { | ||
@@ -27,3 +24,2 @@ attachStaticRoute(method, path, handler, routesStatic); | ||
} | ||
// Dynamic | ||
attachDynamicRoute(method, path, handler, routesDynamic); | ||
@@ -41,3 +37,2 @@ } | ||
} | ||
// Static | ||
const handler = routesStatic[method]?.[path]; | ||
@@ -47,3 +42,2 @@ if (typeof handler !== 'undefined') { | ||
} | ||
// Dynamic | ||
for (const route of routesDynamic[method] ?? []){ | ||
@@ -59,3 +53,2 @@ const match = path.match(route.path); | ||
} | ||
// Not Found | ||
throw createError(404, 'Route does not exist', { | ||
@@ -79,4 +72,3 @@ cause: { | ||
'HEAD' | ||
] // ANY excluded by design | ||
; | ||
]; | ||
const attachStaticRoute = (method, path, handler, routesType)=>{ | ||
@@ -93,4 +85,3 @@ if (method === 'ANY') { | ||
routesType[method][path] = handler; | ||
routesType[method][path + '/'] = handler // Optional `/` | ||
; | ||
routesType[method][path + '/'] = handler; | ||
}; | ||
@@ -108,4 +99,3 @@ const attachDynamicRoute = (method, path, handler, routesType)=>{ | ||
path = path.replace(regexpDynamicWildcards, '/?(?<$1>.*)').replace(regexpDynamicParameters, '/(?<$1>[^/]+)'); | ||
path = new RegExp(`^${path}/?$`) // Adds in optional `/` | ||
; | ||
path = new RegExp(`^${path}/?$`); | ||
routesType[method].push({ | ||
@@ -117,3 +107,2 @@ path, | ||
const pickVersion = (event)=>{ | ||
// '1.0' is a safer default | ||
return event.version ?? (event.method ? 'vpc' : '1.0'); | ||
@@ -120,0 +109,0 @@ }; |
{ | ||
"name": "@middy/http-router", | ||
"version": "5.0.2", | ||
"version": "5.0.3", | ||
"description": "HTTP event router for the middy framework", | ||
@@ -63,9 +63,9 @@ "type": "module", | ||
"dependencies": { | ||
"@middy/util": "5.0.2" | ||
"@middy/util": "5.0.3" | ||
}, | ||
"devDependencies": { | ||
"@middy/core": "5.0.2", | ||
"@middy/core": "5.0.3", | ||
"@types/aws-lambda": "^8.10.97" | ||
}, | ||
"gitHead": "6d17e155237022f2a0abd095ac7cd99ebfc7fc71" | ||
"gitHead": "87660575a7ac2b52e4153c407a4c63c9449dcd0d" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9836
138
+ Added@middy/util@5.0.3(transitive)
- Removed@middy/util@5.0.2(transitive)
Updated@middy/util@5.0.3