src/components/server.js
/**
   * Init the server by setting/using all his middlewares :
   *  - Morgan to log the request
   *  - CORS to only GET, POST.
   *  - Static serve to /assets
   *
   *  - Finally, actives the routers for the server.
   * @param {Array<Router>} routers - All routes handled by the server.
   * @return {Promise} a pending promise containing the app instance.
   */
Init the server by setting/using all his middlewares :
- Morgan to log the request
- CORS to only GET, POST.
- Static serve to /assets

- Finally, actives the routers for the server.
@param {Array} routers - All routes handled by the server.
@return {Promise} a pending promise containing the app instance.
Init the server by setting / using all his middlewares : - Morgan to log the request - CORS to only GET POST . - Static serve to / assets - Finally actives the routers for the server . @param { Array } routers - All routes handled by the server . @return { Promise } a pending promise containing the app instance .
init(routers = []) {
    return new Promise((resolve, reject) => {
      Logger.info('[SERVER]\t Use Middleware : Morgan(short)');
      this.app_.use(kMorgan('short'));
      Logger.info('[SERVER]\t Use Middleware : Morgan(combined) req:400>file');
      this.app_.use(kMorgan('combined', {
        skip: (ctxt, next) => ctxt.statusCode < 400,
        stream: Logger.fsStream,
      }));
      Logger.info('[SERVER]\t Use Middleware : CORS(GET,POST)');
      this.app_.use(kCORS({
        allowMethods: ['GET', 'POST'],
      }));
      Logger.info('[SERVER]\t Use Middleware : Static Serve(/assets/*)');
      const staticFolder = path.join(__dirname, '..', '..', 'assets');
      this.app_.use(kMount('/assets', kStaticServe(staticFolder)));
      Logger.info('[SERVER]\t Use Middleware : JSON(all responses)');
      this.app_.use(kJSON());
      Logger.info('[SERVER]\t Use Middleware : HandleError(all responses)');
      this.app_.use(kHandleError(Logger.error));
      if (!Util.isEmptyOrNull(routers))
        this.initRouters(routers);
      resolve();
    });
  }
init ( routers = [ ] ) { return new Promise ( ( resolve , reject ) => { Logger . info ( '[SERVER]\t Use Middleware : Morgan(short)' ) ; this . app_ . use ( kMorgan ( 'short' ) ) ; Logger . info ( '[SERVER]\t Use Middleware : Morgan(combined) req:400>file' ) ; this . app_ . use ( kMorgan ( 'combined' , { skip : ( ctxt , next ) => ctxt . statusCode < 400 , stream : Logger . fsStream , } ) ) ; Logger . info ( '[SERVER]\t Use Middleware : CORS(GET,POST)' ) ; this . app_ . use ( kCORS ( { allowMethods : [ 'GET' , 'POST' ] , } ) ) ; Logger . info ( '[SERVER]\t Use Middleware : Static Serve(/assets/*)' ) ; const staticFolder = path . join ( __dirname , '..' , '..' , 'assets' ) ; this . app_ . use ( kMount ( '/assets' , kStaticServe ( staticFolder ) ) ) ; Logger . info ( '[SERVER]\t Use Middleware : JSON(all responses)' ) ; this . app_ . use ( kJSON ( ) ) ; Logger . info ( '[SERVER]\t Use Middleware : HandleError(all responses)' ) ; this . app_ . use ( kHandleError ( Logger . error ) ) ; if ( ! Util . isEmptyOrNull ( routers ) ) this . initRouters ( routers ) ; resolve ( ) ; } ) ; }
Init the server by setting/using all his middlewares :
  - Morgan to log the request
  - CORS to only GET, POST.
Init the server by setting / using all his middlewares : - Morgan to log the request - CORS to only GET POST .
// Log any req // Log error on request in files. // Serve static files // JSON all in the ctx.body // Default handler for error // if not set in the router.