src/index.js
function startSkeletonApplication(options) {
  debug('Starting to create application skeleton');
  const configWithDefaults = defaults(
    options, {
      redirects: {
        'documentation-from-root': {
          match: /^\/$/,
          target: '/docs',
        },
      },
      ioc: {
      },
      customMiddleware: {
        beforeSwagger: [],
        afterSwagger: [],
        beforeController: [],
      },
      codegen: {
        controllerStubFolder: 'controllers',
        temporaryDirectory: './.temp',
        templateSet: templates,
      },
      service: {
        listenPort: 10010,
      },
      cors: {
      },
    });

  // If the swagger input is a string, then load it as a filename
  const swaggerFile = configWithDefaults.service.swagger;
  const swagger = typeof swaggerFile === 'string' ?
    yamljs.load(swaggerFile) : swaggerFile;

  // Create service instances
  const app = connect();
  const ioc = connectIoc(configWithDefaults.ioc);

  // Generate custom application code
  generateApplicationCode(
    swagger,
    configWithDefaults.codegen);

  initializeSwagger(swagger, (middleware) => {
    // Pre-request handling middleware
    app.use(query());                                    // Query-string parsing
    app.use(fiddleware.respondJson());                   // res.json(data, status) support.
    app.use(ioc.middleware);                             // Somersault IoC for controllers.
    app.use(cors(configWithDefaults.cors));              // Cross-origin
    app.use(cookieParser());
    // Custom middleware
    for (const item of configWithDefaults.customMiddleware.beforeSwagger) {
      app.use(item);
    }

    // Swagger-tools middleware
    app.use(middleware.swaggerMetadata());
    app.use(middleware.swaggerValidator());

    for (const item of configWithDefaults.customMiddleware.beforeController) {
      app.use(item);
    }

    app.use(middleware.swaggerRouter({
      controllers: path.join(
        configWithDefaults.codegen.temporaryDirectory,
        configWithDefaults.codegen.controllerStubFolder),
    }));
    app.use(middleware.swaggerUi());

    // Post-request handling middleware
    app.use(redirect(configWithDefaults.redirects));      // Redirect / to /docs

    // Custom middleware
    for (const item of configWithDefaults.customMiddleware.afterSwagger) {
      app.use(item);
    }

    app.use(errorHandler());                              // When there's an exception.

    const server = app.listen(configWithDefaults.service.listenPort);
    app.close = function closeServer() {
      server.close();
    };
  });

  return app;
}
function startSkeletonApplication(options) {
  debug('Starting to create application skeleton');
  const configWithDefaults = defaults(
    options, {
      redirects: {
        'documentation-from-root': {
          match: /^\/$/,
          target: '/docs',
        },
      },
      ioc: {
      },
      customMiddleware: {
        beforeSwagger: [],
        afterSwagger: [],
        beforeController: [],
      },
      codegen: {
        controllerStubFolder: 'controllers',
        temporaryDirectory: './.temp',
        templateSet: templates,
      },
      service: {
        listenPort: 10010,
      },
      cors: {
      },
    });

  // If the swagger input is a string, then load it as a filename
  const swaggerFile = configWithDefaults.service.swagger;
  const swagger = typeof swaggerFile === 'string' ?
    yamljs.load(swaggerFile) : swaggerFile;

  // Create service instances
  const app = connect();
  const ioc = connectIoc(configWithDefaults.ioc);

  // Generate custom application code
  generateApplicationCode(
    swagger,
    configWithDefaults.codegen);

  initializeSwagger(swagger, (middleware) => {
    // Pre-request handling middleware
    app.use(query());                                    // Query-string parsing
    app.use(fiddleware.respondJson());                   // res.json(data, status) support.
    app.use(ioc.middleware);                             // Somersault IoC for controllers.
    app.use(cors(configWithDefaults.cors));              // Cross-origin
    app.use(cookieParser());
    // Custom middleware
    for (const item of configWithDefaults.customMiddleware.beforeSwagger) {
      app.use(item);
    }

    // Swagger-tools middleware
    app.use(middleware.swaggerMetadata());
    app.use(middleware.swaggerValidator());

    for (const item of configWithDefaults.customMiddleware.beforeController) {
      app.use(item);
    }

    app.use(middleware.swaggerRouter({
      controllers: path.join(
        configWithDefaults.codegen.temporaryDirectory,
        configWithDefaults.codegen.controllerStubFolder),
    }));
    app.use(middleware.swaggerUi());

    // Post-request handling middleware
    app.use(redirect(configWithDefaults.redirects));      // Redirect / to /docs

    // Custom middleware
    for (const item of configWithDefaults.customMiddleware.afterSwagger) {
      app.use(item);
    }

    app.use(errorHandler());                              // When there's an exception.

    const server = app.listen(configWithDefaults.service.listenPort);
    app.close = function closeServer() {
      server.close();
    };
  });

  return app;
}
function startSkeletonApplication ( options ) { debug ( 'Starting to create application skeleton' ) ; const configWithDefaults = defaults ( options , { redirects : { 'documentation-from-root' : { match : / ^\/$ / , target : '/docs' , } , } , ioc : { } , customMiddleware : { beforeSwagger : [ ] , afterSwagger : [ ] , beforeController : [ ] , } , codegen : { controllerStubFolder : 'controllers' , temporaryDirectory : './.temp' , templateSet : templates , } , service : { listenPort : 10010 , } , cors : { } , } ) ; // If the swagger input is a string, then load it as a filename const swaggerFile = configWithDefaults . service . swagger ; const swagger = typeof swaggerFile === 'string' ? yamljs . load ( swaggerFile ) : swaggerFile ; // Create service instances const app = connect ( ) ; const ioc = connectIoc ( configWithDefaults . ioc ) ; // Generate custom application code generateApplicationCode ( swagger , configWithDefaults . codegen ) ; initializeSwagger ( swagger , ( middleware ) => { // Pre-request handling middleware app . use ( query ( ) ) ; // Query-string parsing app . use ( fiddleware . respondJson ( ) ) ; // res.json(data, status) support. app . use ( ioc . middleware ) ; // Somersault IoC for controllers. app . use ( cors ( configWithDefaults . cors ) ) ; // Cross-origin app . use ( cookieParser ( ) ) ; // Custom middleware for ( const item of configWithDefaults . customMiddleware . beforeSwagger ) { app . use ( item ) ; } // Swagger-tools middleware app . use ( middleware . swaggerMetadata ( ) ) ; app . use ( middleware . swaggerValidator ( ) ) ; for ( const item of configWithDefaults . customMiddleware . beforeController ) { app . use ( item ) ; } app . use ( middleware . swaggerRouter ( { controllers : path . join ( configWithDefaults . codegen . temporaryDirectory , configWithDefaults . codegen . controllerStubFolder ) , } ) ) ; app . use ( middleware . swaggerUi ( ) ) ; // Post-request handling middleware app . use ( redirect ( configWithDefaults . redirects ) ) ; // Redirect / to /docs // Custom middleware for ( const item of configWithDefaults . customMiddleware . afterSwagger ) { app . use ( item ) ; } app . use ( errorHandler ( ) ) ; // When there's an exception. const server = app . listen ( configWithDefaults . service . listenPort ) ; app . close = function closeServer ( ) { server . close ( ) ; } ; } ) ; return app ; }
Initialize the application skeleton
Initialize the application skeleton