/**
 * Main script.
 *
 * This component provides a main script for an HTTP application.
 *
 * This package provides a default service component which uses the [Express][1]
 * framework.  It is expected that most applications will utilize this component,
 * as it eliminates the boilerplate typically found in most Express apps.
 *
 * However, the main script will preferrentially load an application-provided
 * component (at `app/service`), for applications that wish to override the
 * standard boilerplate or use an alternative framework.  This component is
 * expected to provide a function which handles HTTP requests, as defined by
 * Node.js' HTTP [`request` event][2].  For example:
 *
 *     function(req, res) {
 *       res.statusCode = 200;
 *       res.setHeader('Content-Type', 'text/plain');
 *       res.end('Hello World');
 *     }
 *
 * Once the service is created, the gateway between the application and the
 * World Wide Web (WWW) will be instantiated, and requests received will be
 * dispatched to the service for handling.
 *
 * [1]: https://expressjs.com/
 * [2]: https://nodejs.org/api/http.html#http_event_request
 */
exports = module.exports = function(IoC, logger) {
  
  return IoC.create('app/service', { meta: true })
    .then(function(service) {
      // The application-specific service component is annotated with a path at
      // which it it should be mounted.  Create the default service component,
      // which will mount the application-provided service, as well as eliminate
      // boilerplate in the application itself.
      
      // TODO: No need to check for path, just service
      if (service[1].implements.indexOf('http://i.bixbyjs.org/http/Service') != -1
          && service[1].a['@path']) {
        return IoC.create('./service');
      }
      
      return service[0];
    }, function(err) {
      // No application-specific service component is provided.  Create the
      // default service component, which eliminates boilerplate in the
      // application itself.
      if (err.code == 'IMPLEMENTATION_NOT_FOUND' && err.interface == 'app/service') {
        return IoC.create('./service');
      }
      
      throw err;
    })
    .then(function(service) {
      return IoC.create('./gateways')
        .then(function(gateways) {
          // TODO: Implement a way to extend the express app so that it
          //       can map between paths and service names, and used to
          //       announce service in a service registry.
          gateways.forEach(function(gateway) {
            // Dispatch requests to the service, which in this case is an
            // Express app.
            gateway.on('request', service);
            
            // TODO: Remove err from callback signature, and hook up error event
            gateway.listen(function(err) {
              // TODO: service discovery announce
              var addr = this.address();
              logger.info('HTTP server listening on %s:%d', addr.address, addr.port);
            });
          });
        });
    });
};

exports['@implements'] = 'http://i.bixbyjs.org/main';
exports['@require'] = [
  '!container',
  'http://i.bixbyjs.org/Logger'
];

@@ -425,23 +425,19 @@
 at %60app/
-service
+app
 %60), for 
@@ -474,19 +474,16 @@
 ride the
-%0A *
  standar
@@ -483,16 +483,19 @@
 standard
+%0A *
  boilerp
@@ -550,19 +550,16 @@
 onent is
-%0A *
  expecte
@@ -562,16 +562,19 @@
 ected to
+%0A *
  provide
@@ -627,19 +627,16 @@
 fined by
-%0A *
  Node.js
@@ -641,16 +641,19 @@
 js' HTTP
+%0A *
  %5B%60reque
@@ -1214,23 +1214,19 @@
 te('app/
-service
+app
 ', %7B met
@@ -1226,16 +1226,20 @@
 , %7B meta
+data
 : true %7D
@@ -1569,63 +1569,8 @@
    %0A
-      // TODO: No need to check for path, just service%0A
     
@@ -1651,43 +1651,8 @@
 = -1
-%0A          && service%5B1%5D.a%5B'@path'%5D
 ) %7B%0A
@@ -1876,65 +1876,63 @@
 ich 
-eliminates boilerplate in the%0A      // application itself
+uses Express and eliminates common%0A      // boilerplate
 .%0A  
@@ -2003,23 +2003,19 @@
 == 'app/
-service
+app
 ') %7B%0A   

Load app/app rather than app/service.