Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}));
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
}
.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
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' });