Skip to content

Commit

Permalink
feat: create interfaces for middleware usage and for adding routes
Browse files Browse the repository at this point in the history
  • Loading branch information
teclone committed Jul 23, 2018
1 parent 9788d54 commit a8bef61
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/modules/RServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import path from 'path';
import Util from './Util.js';
import http from 'http';
import StaticFileServer from './StaticFileServer.js';
import Router from './Router.js';
import BodyParser from './BodyParser.js';
import _config from '../.rsvrc.json';
import RServerResponse from './RServerResponse.js';
Expand Down Expand Up @@ -115,6 +116,26 @@ export default class {
return config;
}

/**
* adds the given route to the routes array
*@param {string} api - the route api
*@param {string} baseUrl - the base url
*@param {Function} callback - callback function
*@param {Object} [options] - optional configuration options
*/
addRoute(api, ...parameters) {
this.routes.push({api, parameters});
}

/**
* use a middleware
*@param {Function} middleware - the middleware function
*/
use(middleware) {
if (Util.isCallable(middleware))
this.middlewares.push(middleware);
}

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

0 comments on commit a8bef61

Please sign in to comment.