Created
March 17, 2020 00:40
-
-
Save bpinedah/65a27c8bd8cc6486f32939d40f0fc9d3 to your computer and use it in GitHub Desktop.
Router article
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @description Find predicate to get the current route | |
* @param m Method from request | |
* @param p Path from request | |
* @returns {function(*)} | |
* @private | |
*/ | |
_findAndComposeRoute(m, p) { | |
return route => { | |
// PARAMS | |
const { method: _method, path: _path } = route; | |
const isHome = _path.lastIndexOf("/") === _path.length - 1; | |
const methodValidation = _method === m; | |
const _params = this._getPathParams(_path, isHome ? `${p}/`: p); | |
const _matchKeys = Object.keys(_params); | |
const matchValidation = _matchKeys.length > 0; | |
const selected = _method !== "*" ? methodValidation && matchValidation : | |
matchValidation; | |
if (selected) { | |
route.params = _params.params ? {..._params.params} : {}; | |
} | |
return selected; | |
}; | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment