This file contains 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
send: function send(data) { | |
// this is an incomplete example | |
const resp = { | |
statusCode, | |
headers: { | |
"Access-Control-Allow-Origin": "*", | |
"Access-Control-Allow-Credentials": true | |
}, | |
body: JSON.stringify(data) |
This file contains 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 Resolve function to exit from pipeline | |
* @param signal Flag to continue or not on pipeline | |
* @returns {*} | |
* @private | |
*/ | |
const _res = signal => () => ({ | |
statusCode: 200, | |
headers: {}, | |
setHeader: function setHeader(header) { |
This file contains 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
app.post('/test', async (req, res, next) => { | |
req.body.auth = true; | |
return next(req); | |
}, async (req, res) => { | |
console.log("other func", req.body.auth); // true | |
return res.send(req.body.auth); | |
}); |
This file contains 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
app.get('/test/(.*)', async (req, res, next) => { | |
req.test = { pre: true }; | |
return next(req); | |
}); |
This file contains 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 Function to send to the next middleware function | |
* @param idx Current function index | |
* @param length Total of middlewares functions | |
* @private | |
*/ | |
const _next = (idx, length) => e => | |
Promise.resolve(idx === length - 1 && length > 2 ? e : [e]); |
This file contains 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 Create function with middlewares | |
* @param f Middleware functions to execute | |
* @returns {*} | |
* @private | |
*/ | |
const _createPipeline = f => { | |
const signal = { continue: true }; | |
return f.length > 1 ? f.reduce((before, after, idx) => |
This file contains 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 a flat array | |
* @param arr Array to flat | |
* @private | |
*/ | |
const _toFlat = arr => [].concat(...arr); | |
const functions = routesFound.map(i => ([...i.middlewares])); | |
const fns = _toFlat(functions); |
This file contains 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 findPredicate = this._findAndComposeRoute(method.toLowerCase(), routerPath); | |
const routesFound = this._routes.filter(findPredicate); |
This file contains 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
v2-app: | |
handler: router-test.main | |
events: | |
- http: | |
path: v2/{proxy+} | |
method: ANY | |
cors: true | |
authorizer: aws_iam |
This file contains 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 Function to generate handler for lambda | |
* @returns {function(*)} | |
*/ | |
toLambda() { | |
return async event => { | |
// FUNCTIONS HELPERS | |
/** | |
* @description Get a flat array | |
* @param arr Array to flat |
NewerOlder