alb-router
Version:
A user-friendly router for Amazon Application Load Balancer paths. Effortlessly match URLs, extract parameters, and handle routing in Node.js.
45 lines • 1.51 kB
JavaScript
// src/index.ts
import { match } from "path-to-regexp";
var extractParams = function(path, method, routes) {
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
try {
for(var _iterator = routes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
var route = _step.value;
var matchFunc = match(route.pattern, {
decode: decodeURIComponent
});
var matched = matchFunc(path);
if (matched && route.methods[method]) {
var params = {};
for(var key in matched.params){
if (typeof matched.params[key] === "string") {
params[key] = matched.params[key];
}
}
return {
params: params,
handler: route.methods[method]
};
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally{
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally{
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return {
params: {},
handler: null
};
};
export { extractParams };
//# sourceMappingURL=index.mjs.map