text: 'use strict';
  
  var loopback = require('loopback');
  var boot = require('loopback-boot');
  var bodyParser = require('body-parser');
  
  var app = module.exports = loopback();
  
  // Passport configurators..
  var loopbackPassport = require('loopback-component-passport');
  var PassportConfigurator = loopbackPassport.PassportConfigurator;
  var passportConfigurator = new PassportConfigurator(app);
  
  // attempt to build the providers/passport config
  var config = {};
  try {
    config = require('../providers');
  } catch (err) {
    console.trace(err);
    process.exit(1); // fatal
  }
  
  app.start = function() {
    // start the web server
    return app.listen(function() {
      app.emit('started');
      var baseUrl = app.get('url').replace(/\/$/, '');
      console.log('Web server listening at: %s', baseUrl);
      if (app.get('loopback-component-explorer')) {
        var explorerPath = app.get('loopback-component-explorer').mountPath;
        console.log('Browse your REST API at %s%s', baseUrl, explorerPath);
      }
    });
  };
  
  // boot scripts mount components like REST API
  boot(app, __dirname);
  
  // to support JSON-encoded bodies
  app.middleware('parse', bodyParser.json());
  // to support URL-encoded bodies
  app.middleware('parse', bodyParser.urlencoded({
    extended: true,
  }));
  
  // The access token is only available after boot
  app.middleware('auth', loopback.token({
    model: app.models.accessToken,
  }));
  
  passportConfigurator.init();
  
  passportConfigurator.setupModels({
    userModel: app.models.user,
    userIdentityModel: app.models.userIdentity,
    userCredentialModel: app.models.userCredential,
  });
  for (var s in config) {
    var c = config[s];
    c.session = c.session !== false;
    passportConfigurator.configureProvider(s, c);
  }
  
  // start the server if `$ node server.js`
  if (require.main === module) {
    app.start();
  }
  