All files / ima/router ServerRouter.js

88.89% Statements 8/9
25% Branches 1/4
80% Functions 4/5
88.89% Lines 8/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69                3x             2x                         3x             3x             3x             2x                           1x       3x  
import ns from '../namespace';
import AbstractRouter from './AbstractRouter';
import Request from './Request';
import Response from './Response';
import RouteFactory from './RouteFactory';
import Dispatcher from '../event/Dispatcher';
import PageManager from '../page/manager/PageManager';
 
ns.namespace('ima.router');
 
/**
 * The server-side implementation of the {@codelink Router} interface.
 */
export default class ServerRouter extends AbstractRouter {
  static get $dependencies() {
    return [PageManager, RouteFactory, Dispatcher, Request, Response];
  }
 
  /**
	 * Initializes the router.
	 *
	 * @param {PageManager} pageManager The current page manager.
	 * @param {RouteFactory} factory The router factory used to create routes.
	 * @param {Dispatcher} dispatcher Dispatcher fires events to app.
	 * @param {Request} request The current HTTP request.
	 * @param {Response} response The current HTTP response.
	 */
  constructor(pageManager, factory, dispatcher, request, response) {
    super(pageManager, factory, dispatcher);
 
    /**
		 * The current HTTP request.
		 *
		 * @type {Request}
		 */
    this._request = request;
 
    /**
		 * The current HTTP response.
		 *
		 * @type {Response}
		 */
    this._response = response;
  }
 
  /**
	 * @inheritdoc
	 */
  getPath() {
    return this._extractRoutePath(this._request.getPath());
  }
 
  /**
	 * @inheritdoc
	 */
  listen() {
    return this;
  }
 
  /**
	 * @inheritdoc
	 */
  redirect(url = '/', options = {}) {
    this._response.redirect(url, options.httpStatus || 302);
  }
}
 
ns.ima.router.ServerRouter = ServerRouter;