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 => { |
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 Get path parameters by router route | |
* @param routePath Path from route | |
* @param requestPath Path from request | |
* @returns {{params: {}, base: *}} | |
* @private | |
*/ | |
_getPathParams(routePath, requestPath) { | |
const { match } = require("path-to-regexp"); | |
const _match = match(routePath, {decode: decodeURIComponent}); |
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
const route = { | |
path: "/users", | |
method: "get", | |
middlewares: [ | |
[Function], | |
[Function], | |
[Function] | |
} | |
} |
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
const _protoRouter = { | |
_routes: [], | |
/** | |
* @description Add new route to list | |
* @param method HTTP method from request | |
* @param path Route path to add | |
* @param middlewares Middlewares functions to add | |
* @private | |
*/ | |
_addRoutes(method, path, middlewares) { |
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
router.get('/users', async (req, res) => { | |
// Get information from DB, files, etc and send it. | |
return res.send([...]); | |
}); |
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
pip.then(r => console.log(r)); |
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
const p1 = (n) => new Promise(resolve => { | |
setTimeout(() => resolve(n * 2), 3000); | |
}); | |
const p2 = (n) => new Promise(resolve => { | |
setTimeout(() => resolve(n + 1), 2000); | |
}); | |
const p3 = (n) => new Promise(resolve => { | |
setTimeout(() => resolve(n + 3), 1000); | |
}); | |
const pipeP = (...fns) => ( |
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
const pipeP = (...fns) => ( | |
fns.reduce((f, g) => x => f(x).then(g)) | |
); |
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
const pipe = (...fns) => x => fns.reduce((f, m) => m(f), x); | |
const fn1 = n => n * 2; | |
const fn2 = n => n + 2; | |
const fn3 = n => n - 4; | |
const pip = pipe( | |
fn1, | |
fn2, | |
fn3 | |
)(10); |
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
const p1 = (n) => new Promise(resolve => { | |
setTimeout(() => resolve(n * 2), 3000); | |
}); | |
const p2 = (n) => new Promise(resolve => { | |
setTimeout(() => resolve(n + 1), 2000); | |
}); | |
const p3 = (n) => new Promise(resolve => { | |
setTimeout(() => resolve(n + 3), 1000); | |
}); |