Skip to content

Commit

Permalink
feat(router): creat the Router module.
Browse files Browse the repository at this point in the history
The router module provides routing functionality, with api endpoints, regex based routing, clean url
support, parameter capturing, and lots more
  • Loading branch information
teclone committed Jul 20, 2018
1 parent 0114d14 commit 3eabdb1
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/modules/Router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* mini Router module.
* Handles Routing. supports parameter catching and allows data type enforcement
*/

export default class Router {

/**
*@param {string} url - the request url
*@param {string} method - the request method
*@param {http.IncomingMessage} request - the request instance
*@param {http.ServerResponse} response - the response instance
*@param {Array} middlewares - Array of middlewares
*@returns {Router}
*/
constructor(url, method, request, response, middlewares) {

this.resolved = false;
this.request = request;
this.response = response;
this.middlewares = middlewares;

this.url = url.toLowerCase().replace(/[#?].*$/, '').replace(/^\/+/, '').replace(/\/+$/, '');
this.method = method.toUpperCase();

this.params = []; //create a simple [paramName, paramValue] tuple
}

/**
* return class identifier
*/
get [Symbol.toStringTag]() {
return 'Router';
}
}

0 comments on commit 3eabdb1

Please sign in to comment.