UNPKG

acady-api-builder

Version:
47 lines 1.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RouteMatchingHelper = void 0; class RouteMatchingHelper { static match(apiRoute, apiRequest) { if (apiRoute.method !== 'ANY') { if (apiRoute.method !== apiRequest.method) { return false; } } else { if (apiRoute.path === '/') { return true; } } const routePathParts = apiRoute.path.split('/'); const requestPathParts = apiRequest.pathName.split('/'); const pathParams = {}; for (let i = 1; i < routePathParts.length; i++) { let routePathPart = routePathParts[i]; let requestPathPart = requestPathParts[i] ? decodeURIComponent(requestPathParts[i]) : null; if (!requestPathPart) { return false; } if (routePathPart.startsWith(':')) { pathParams[routePathPart.substr(1)] = requestPathPart; } else if (requestPathPart !== routePathPart) { return false; } } for (let i = 1; i < requestPathParts.length; i++) { let routePathPart = routePathParts[i]; // let requestPathPart: string = decodeURIComponent(requestPathParts[i]); if (!routePathPart) { return false; } } apiRequest.pathParams = pathParams; apiRequest.routePath = apiRoute.path; return true; } } exports.RouteMatchingHelper = RouteMatchingHelper; //# sourceMappingURL=route-matching-helper.js.map