@tigojs/lambda-router
This is a router helper for tigo lambda users, based on koa-tree-router.
Usage
Firstly, you should add it to the server via npm install
.
Then you can use it like this in your lambda:
const Router = require('@tigojs/lambda-router');
const router = new Router();
// your function
async function myBusinessFunction(ctx, next) {
// your code
}
// path is the relative path to your router.
router.get('/route', myBusinessFunction);
async function handleRequest(ctx) {
// MUST HAVE THIS LINE, OHTERWISE THE ROUTER WILL NOT WORK!
return router.route(ctx);
// AND ALSO, YOU SHOULD REGISTER ALL YOUR ROUTES BEFORE YOU CALL THIS FUNCTION.
}
module.exports = handleRequest;
License
MIT