-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
39 lines (39 loc) · 1.33 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const mockRequire = require('./core/mock-require')
global.watchRequire = mockRequire.watchRequire
const Database = require('./core/database')
let Config
const Router = require('./core/router')
const express = require('express')
const fs = require('fs-extra')
const path = require('path')
const Cache = require('./core/cache-handler-loader')
const ConfigLoader = require('./core/config-loader')
const ExpressAsyncWrapper = require('./core/express-async-wrapper')
module.exports = async function (loadroutes = true) {
Config = ConfigLoader()
// expose to global to convenient for require module
const RouterBaseDir = path.resolve(__dirname, 'src', Config.server.route_dir)
console.info('Loading Models....')
const DB = await Database(Config)
console.info('Done!\n')
const context = {
Model: DB.models,
Definition: DB.definitions,
Sequelize: DB.sequelize,
Config,
Wrapper: ExpressAsyncWrapper
}
console.info('Loading cache handlers....')
const cache = await Cache(path.resolve(__dirname, 'src/CacheHandlers'), context)
console.info('Done!\n')
context.Cache = cache
let app
if (loadroutes === true) {
console.info('Loading Routes....')
let [router, routerTree] = await Router(RouterBaseDir, context)
console.info('Done!\n')
app = express()
app.use('/', router)
}
return { app, context }
}