-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (35 loc) · 1.22 KB
/
index.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
require('dotenv').config()
const web = require('express')()
const redis = require('redis')
const router = require('./routing/routes')
const { DBController } = require('./controllers/dbController')
const { UpdateController } = require('./controllers/updateController')
const scheduler = require('node-cron')
const { Logger } = require('./utils/logger')
const APIPORT = process.env.APIPORT ? process.env.APIPORT : 80
const redisClient = redis.createClient()
// Проверяем задан ли токен администратора в .env
if (!process.env.ADMIN_TOKEN) {
console.error('ERROR: No ADMIN_TOKEN in .env file')
process.exit()
}
const init = async () => {
Logger.log('Starting...')
redisClient.on('error', (err) => {
Logger.log('Redis connection failed')
process.exit()
})
redisClient.on('connect', () => {
Logger.log('Redis connection established')
})
redisClient.connect()
await DBController.init(redisClient)
web.use('/api', router)
web.listen(APIPORT)
Logger.log('Web server started on port ' + APIPORT)
scheduler.schedule('* * * * *', async () => {
await UpdateController.update()
})
Logger.log('Update scheduler started')
}
init()