This repository has been archived by the owner on Mar 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
49 lines (42 loc) · 1.45 KB
/
app.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
40
41
42
43
44
45
46
47
48
49
// istanbul ignore file
const config = require('./config')
require('./config/passport')
require('express-async-errors')
const passport = require('passport')
const express = require('express')
const app = express()
require('express-ws')(app)
if (config.get('proxy')) app.set('trust proxy', config.get('proxy'))
module.exports = app
.use(require('./middlewares/access-logger'))
.use(require('express-request-id')())
.use(require('./middlewares/express-logger'))
.use(require('helmet')())
.use(require('cors')({ origin: true }))
.use(require('./middlewares/session'))
.use(require('./middlewares/ratelimiter'))
.use(express.json())
.use(require('express-query-boolean')())
.use(passport.initialize())
.use(passport.session())
.use(require('./routes'))
// eslint-disable-next-line no-unused-vars
.use((req, res) => res.sendStatus(404))
.use(require('./middlewares/error-handler'))
/* -------------------- Asynchronous app init -------------------- */
const fs = require('fs')
const log = require('./lib/logger')
module.exports.initialize = async () => {
const models = await fs.promises.readdir(`${__dirname}/models`)
const inits = models
.filter(
file =>
file.endsWith('.js') && file !== 'base.js' && file !== 'session.js'
)
.map(model => {
const modelClass = require(`./models/${model}`)
log.info(`Initializing model ${model}`)
return modelClass.fetchTableMetadata()
})
await Promise.all(inits)
}