How to use the awilix-koa.loadControllers function in awilix-koa

To help you get started, we’ve selected a few awilix-koa examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mollyywang / koa2-mongodb-jwt-server / src / lib / server.js View on Github external
}));

  app
    // Top middleware is the error handler.
    .use(errorHandler)
    // Compress all responses.
    .use(compress())
    // Adds ctx.ok(), ctx.notFound(), etc..
    .use(respond())
    // Parses request bodies.
    .use(bodyParser())
    // Creates an Awilix scope per request. Check out the awilix-koa
    // docs for details: https://github.com/jeffijoe/awilix-koa
    .use(scopePerRequest(container))
    // load routes 
    .use(loadControllers('../routes/*.js', { cwd: __dirname }))

  //open database 开启数据库
  dbconnect()

  // Create http server 开启服务
  const server = http.createServer(app.callback())
  // Add a `close` event listener 监听应用关闭
  server.on('close', () => {
    // tear down database connections, etc.
    logger.debug('Server closing, bye!')
  })
  logger.debug('Server created, ready to listen', { scope: 'startup' })
  return server
}
github jeffijoe / koa-es7-boilerplate / src / lib / server.js View on Github external
.use(errorHandler)
    // Compress all responses.
    .use(compress())
    // Adds ctx.ok(), ctx.notFound(), etc..
    .use(respond())
    // Handles CORS.
    .use(cors())
    // Parses request bodies.
    .use(bodyParser())
    // Creates an Awilix scope per request. Check out the awilix-koa
    // docs for details: https://github.com/jeffijoe/awilix-koa
    .use(scopePerRequest(container))
    // Create a middleware to add request-specific data to the scope.
    .use(registerContext)
    // Load routes (API "controllers")
    .use(loadControllers('../routes/*.js', { cwd: __dirname }))
    // Default handler when nothing stopped the chain.
    .use(notFoundHandler)

  // Creates a http server ready to listen.
  const server = http.createServer(app.callback())

  // Add a `close` event listener so we can clean up resources.
  server.on('close', () => {
    // You should tear down database connections, TCP connections, etc
    // here to make sure Jest's watch-mode some process management
    // tool does not release resources.
    logger.debug('Server closing, bye!')
  })

  logger.debug('Server created, ready to listen', { scope: 'startup' })
  return server
github inkubux / MediaSpeed / src / lib / server.js View on Github external
let buildFolder = process.env.NODE_ENV !== ' development' ? '/build' : '';
    app.use(
        serveStatic({
            rootPath: '/web',
            rootDir: path.join(__dirname, '/../../frontend', buildFolder),
            notFoundFile: 'index.html'
        })
    );

    // Creates an Awilix scope per request. Check out the awilix-koa
    // docs for details: https://github.com/jeffijoe/awilix-koa
    app.use(scopePerRequest(container));

    // Load routes (API "controllers")
    app.use(loadControllers('../routes/*.js', { cwd: __dirname }));
    // Default handler when nothing stopped the chain.
    app.use(notFoundHandler);

    // Creates a http server ready to listen.
    const server = http.createServer(app.callback());

    // Add a `close` event listener so we can clean up resources.
    server.on('close', () => {
        // You should tear down database connections, TCP connections, etc
        // here to make sure Jest's watch-mode some process management
        // tool does not release resources.
        logger.debug('Server closing, bye!');
    });

    logger.debug('Server created, ready to listen', { scope: 'startup' });

awilix-koa

Awilix helpers for Koa

MIT
Latest version published 10 months ago

Package Health Score

52 / 100
Full package analysis

Similar packages