-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
50 lines (43 loc) · 1.39 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
40
41
42
43
44
45
46
47
48
49
50
import 'dotenv/config'
import Fastify from 'fastify'
import fastifyCors from 'fastify-cors'
import fastifyRedis from 'fastify-redis'
import fastifyStatic from 'fastify-static'
import fastifyCompress from 'fastify-compress'
import ota from './routes/ota.js'
import stats from './routes/stats.js'
import addons from './routes/addons.js'
import builds from './routes/builds.js'
import otaNew from './routes/otaNew.js'
import devices from './routes/devices.js'
import download from './routes/download.js'
import { buildsDir } from './constants.js'
import { connectDB } from './database.js'
const fastify = Fastify({
logger: true
})
// Fastify Plugins
fastify.register(fastifyCors)
fastify.register(fastifyRedis)
fastify.register(fastifyCompress, { global: true })
fastify.register(fastifyStatic, { root: buildsDir })
// API Routes
fastify.register(addons, { prefix: '/addons' })
fastify.register(builds, { prefix: '/builds' })
fastify.register(devices, { prefix: '/devices' })
fastify.register(download, { prefix: '/download' })
fastify.register(ota, { prefix: '/ota' })
fastify.register(otaNew, { prefix: '/ota_v2' })
fastify.register(stats, { prefix: '/stats' })
const startServer = async () => {
await connectDB()
try {
await fastify.ready()
await fastify.listen(process.env.PORT)
console.log('Server Started')
} catch (error) {
fastify.log.error(error)
process.exit(1)
}
}
startServer()