lib/middleware/envMongoDb.js
function getEnvironmentDatabase(req, res, next){
  log.logger.debug('process getEnvironmentDatabase request', req.originalUrl );

  _getEnvironmentDatabase({
    domain: req.params.domain,
    environment: req.params.environment
  }, function(err, envDb){
    if(err){
      log.logger.error('Failed to get mbaas instance', err);
      return next(common.buildErrorObject({
        err: err,
        msg: 'Failed to get mbaas instance',
        httpCode: 500
      }));
    }

    if(!envDb){
      log.logger.error("No Environment Database Found", err);
      return next(common.buildErrorObject({
        err: new Error("No Environment Database Found"),
        httpCode: 400
      }));
    }

    req.mongoUrl = common.formatDbUri(envDb.dbConf);

    log.logger.debug("Found Environment Database", req.mongoUrl);

    return next();
  });
}
function getEnvironmentDatabase(req, res, next){
  log.logger.debug('process getEnvironmentDatabase request', req.originalUrl );

  _getEnvironmentDatabase({
    domain: req.params.domain,
    environment: req.params.environment
  }, function(err, envDb){
    if(err){
      log.logger.error('Failed to get mbaas instance', err);
      return next(common.buildErrorObject({
        err: err,
        msg: 'Failed to get mbaas instance',
        httpCode: 500
      }));
    }

    if(!envDb){
      log.logger.error("No Environment Database Found", err);
      return next(common.buildErrorObject({
        err: new Error("No Environment Database Found"),
        httpCode: 400
      }));
    }

    req.mongoUrl = common.formatDbUri(envDb.dbConf);

    log.logger.debug("Found Environment Database", req.mongoUrl);

    return next();
  });
}
function getEnvironmentDatabase ( req , res , next ) { log . logger . debug ( 'process getEnvironmentDatabase request' , req . originalUrl ) ; _getEnvironmentDatabase ( { domain : req . params . domain , environment : req . params . environment } , function ( err , envDb ) { if ( err ) { log . logger . error ( 'Failed to get mbaas instance' , err ) ; return next ( common . buildErrorObject ( { err : err , msg : 'Failed to get mbaas instance' , httpCode : 500 } ) ) ; } if ( ! envDb ) { log . logger . error ( "No Environment Database Found" , err ) ; return next ( common . buildErrorObject ( { err : new Error ( "No Environment Database Found" ) , httpCode : 400 } ) ) ; } req . mongoUrl = common . formatDbUri ( envDb . dbConf ) ; log . logger . debug ( "Found Environment Database" , req . mongoUrl ) ; return next ( ) ; } ) ; }
Middleware To Get An Environment Database
Middleware To Get An Environment Database