-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.js
executable file
·40 lines (37 loc) · 944 Bytes
/
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
40
const knex = require('knex')
const knexfile = require('./knexfile')
const { app, sqsService } = require('./server/index')
const log = require('./log')
const config = require('./server/config')
const selectSql = message => {
if (message.sql) {
return message.sql
}
if (message.length && message.length >= 1) {
return message[0].sql
}
return { knex: message }
}
// See https://knexjs.org
const init = {
...knexfile,
log: {
debug(message) {
log.debug(selectSql(message))
},
},
debug: true,
}
log.debug('Migration start')
const knex1 = knex(init)
knex1.migrate.latest().then(() => {
log.debug('Migration finished')
app.listen(app.get('port'), () => {
log.info(`Server listening on port ${app.get('port')}`)
})
// must be created after migration scripts are complete
if (config.sqs.enabled === 'true') {
sqsService.rpQueueConsumer.start()
sqsService.eventQueueConsumer.start()
}
})