server/boot/load-model.js
function(seriesCallback) {
      var entry = {};
      // add catalog
      entry.catalog = defaultCatalog;
      entry['snapshot-id'] = uid;

      entry.document = {
        product: '1.0.0',
        info: {
          name: 'static-product',
          version: '1.0.0',
          title: 'static-product' },
        visibility: {
          view: {
            type: 'public' },
          subscribe: {
            type: 'authenticated' } },
        apis: apis };

      var rateLimit = '100/hour';
      if (process.env[LAPTOP_RATELIMIT]) {
        rateLimit = process.env[LAPTOP_RATELIMIT];
      }

      if (apicCfg && apicCfg.plans && apicCfg.applications) {
        //add the configured plans
        entry.document.plans = {};
        //add plan and its APIs
        for (var p in apicCfg.plans) {
          var plan = apicCfg.plans[p];
          if (typeof plan === 'object') {
            var planApis = {};
            for (var i in plan.apis) {
              var name = plan.apis[i];
              //add the api to plan if only if the api does exist
              if (apis[name]) {
                planApis[name] = {};
              } else {
                logger.warn('Cannot add the invalid api "%s" to plan "%s"',
                        name, p);
              }
            }
            entry.document.plans[p] = {
              apis: planApis,
              'rate-limit': {
                value: plan['rate-limit'] || rateLimit,
                'hard-limit': plan['hard-limit'] } };
          }
        }
      } else {
        //the default plan
        entry.document.plans = {
          default: {
            apis: apis,
            'rate-limit': {
              value: rateLimit,
              'hard-limit': true } } };
      }

      if (logger.debug()) {
        logger.debug('creating static product and attaching apis to plans: %s',
                JSON.stringify(entry, null, 2));
      }

      app.models.product.create(
        entry,
        function(err, mymodel) {
          if (err) {
            logger.error(err);
            seriesCallback(err);
            return;
          }
          logger.debug('%s created: %j', 'product', mymodel);
          seriesCallback();
        });
    }
function(seriesCallback) {
      var entry = {};
      // add catalog
      entry.catalog = defaultCatalog;
      entry['snapshot-id'] = uid;

      entry.document = {
        product: '1.0.0',
        info: {
          name: 'static-product',
          version: '1.0.0',
          title: 'static-product' },
        visibility: {
          view: {
            type: 'public' },
          subscribe: {
            type: 'authenticated' } },
        apis: apis };

      var rateLimit = '100/hour';
      if (process.env[LAPTOP_RATELIMIT]) {
        rateLimit = process.env[LAPTOP_RATELIMIT];
      }

      if (apicCfg && apicCfg.plans && apicCfg.applications) {
        //add the configured plans
        entry.document.plans = {};
        //add plan and its APIs
        for (var p in apicCfg.plans) {
          var plan = apicCfg.plans[p];
          if (typeof plan === 'object') {
            var planApis = {};
            for (var i in plan.apis) {
              var name = plan.apis[i];
              //add the api to plan if only if the api does exist
              if (apis[name]) {
                planApis[name] = {};
              } else {
                logger.warn('Cannot add the invalid api "%s" to plan "%s"',
                        name, p);
              }
            }
            entry.document.plans[p] = {
              apis: planApis,
              'rate-limit': {
                value: plan['rate-limit'] || rateLimit,
                'hard-limit': plan['hard-limit'] } };
          }
        }
      } else {
        //the default plan
        entry.document.plans = {
          default: {
            apis: apis,
            'rate-limit': {
              value: rateLimit,
              'hard-limit': true } } };
      }

      if (logger.debug()) {
        logger.debug('creating static product and attaching apis to plans: %s',
                JSON.stringify(entry, null, 2));
      }

      app.models.product.create(
        entry,
        function(err, mymodel) {
          if (err) {
            logger.error(err);
            seriesCallback(err);
            return;
          }
          logger.debug('%s created: %j', 'product', mymodel);
          seriesCallback();
        });
    }
function ( seriesCallback ) { var entry = { } ; // add catalog entry . catalog = defaultCatalog ; entry [ 'snapshot-id' ] = uid ; entry . document = { product : '1.0.0' , info : { name : 'static-product' , version : '1.0.0' , title : 'static-product' } , visibility : { view : { type : 'public' } , subscribe : { type : 'authenticated' } } , apis : apis } ; var rateLimit = '100/hour' ; if ( process . env [ LAPTOP_RATELIMIT ] ) { rateLimit = process . env [ LAPTOP_RATELIMIT ] ; } if ( apicCfg && apicCfg . plans && apicCfg . applications ) { //add the configured plans entry . document . plans = { } ; //add plan and its APIs for ( var p in apicCfg . plans ) { var plan = apicCfg . plans [ p ] ; if ( typeof plan === 'object' ) { var planApis = { } ; for ( var i in plan . apis ) { var name = plan . apis [ i ] ; //add the api to plan if only if the api does exist if ( apis [ name ] ) { planApis [ name ] = { } ; } else { logger . warn ( 'Cannot add the invalid api "%s" to plan "%s"' , name , p ) ; } } entry . document . plans [ p ] = { apis : planApis , 'rate-limit' : { value : plan [ 'rate-limit' ] || rateLimit , 'hard-limit' : plan [ 'hard-limit' ] } } ; } } } else { //the default plan entry . document . plans = { default : { apis : apis , 'rate-limit' : { value : rateLimit , 'hard-limit' : true } } } ; } if ( logger . debug ( ) ) { logger . debug ( 'creating static product and attaching apis to plans: %s' , JSON . stringify ( entry , null , 2 ) ) ; } app . models . product . create ( entry , function ( err , mymodel ) { if ( err ) { logger . error ( err ) ; seriesCallback ( err ) ; return ; } logger . debug ( '%s created: %j' , 'product' , mymodel ) ; seriesCallback ( ) ; } ) ; }
3. create one "product" with all the apis defined
3 . create one product with all the apis defined