Skip to content

Commit

Permalink
feat: create the route runner that specifically executes routes
Browse files Browse the repository at this point in the history
  • Loading branch information
teclone committed Jul 23, 2018
1 parent a8bef61 commit 380216e
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/modules/RServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,49 @@ export default class {
this.middlewares.push(middleware);
}

/**
* runs all request routes
*@param {string} url - request url
*@param {string} method - request method
*@param {http.IncomingMessage} request - the request object
*@param {RServerResponse} response - the response object
*@returns {boolean}
*/
runRoutes(url, method, request, response) {
//create router and run routes
let router = new Router(url, method, request, response, this.middlewares);
//run routes
for (const route of this.routes) {
switch(route.api.toLowerCase()) {
case 'get':
router.get(...route.parameters);
break;
case 'post':
router.post(...route.parameters);
break;
case 'delete':
router.delete(...route.parameters);
break;
case 'put':
router.put(...route.parameters);
break;
case 'route':
router.route(...route.parameters);
break;
case 'head':
router.head(...route.parameters);
break;
case 'options':
router.options(...route.parameters);
break;
}

if(router.resolved)
return true;
}
return false;
}

/**
* handle request data event
*/
Expand Down

0 comments on commit 380216e

Please sign in to comment.