Skip to content

Commit

Permalink
feat: add ability to set or override middlewares
Browse files Browse the repository at this point in the history
  • Loading branch information
teclone committed Jul 25, 2018
1 parent 67bd8fa commit b78d27f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/modules/Router.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ export default class Router {
*@param {string} method - the request method
*@param {http.IncomingMessage} request - the request instance
*@param {RServerResponse} response - the response instance
*@param {Array} middlewares - Array of middlewares
*@returns {Router}
*@param {Array} [middlewares] - Array of middlewares
*/
constructor(url, method, request, response, middlewares) {

this.resolved = false;
this.request = request;
this.response = response;
this.middlewares = middlewares;
this.middlewares = middlewares || [];

this.url = url.toLowerCase().replace(/[#?].*$/, '').replace(/^\/+/, '').replace(/\/+$/, '');
this.method = method.toUpperCase();
Expand All @@ -34,6 +33,14 @@ export default class Router {
return 'Router';
}

/**
* sets or overrides the existing middlewares
*@param {Array} middlewares - array of middlewares
*/
middlewares(middlewares) {
this.middlewares = middlewares;
}

/**
* runs the routes template callback function
*@param {Function} - route callback function
Expand Down

0 comments on commit b78d27f

Please sign in to comment.