ddstats-server/index.js

47 lines
1.1 KiB
JavaScript
Raw Normal View History

2021-10-06 20:36:20 +02:00
/**
* This is the entrypoint for 'DDStats'.
* DDStats is a custom API that servers statistics from the DDRace Network-
* @author BurnyLlama <xmpp:burnyllama@qwik.space>
*/
2021-09-25 12:11:27 +02:00
import express from 'express'
2021-09-25 17:47:05 +02:00
import dotenv from 'dotenv'
2021-10-30 21:39:21 +02:00
import njk from 'nunjucks'
import initLog from './libs/utils/log.js'
2021-10-30 21:39:21 +02:00
import routes from './routes/routes.js'
2021-11-04 19:47:40 +01:00
import api from './api/api.js'
import { generateDB } from './libs/database/generate.js'
import { dbInit } from './libs/database/init.js'
import { downloadEssentialData } from './libs/download/dowload.js'
2021-10-30 21:39:21 +02:00
2021-09-29 20:29:06 +02:00
const log = initLog("[ MAIN ]")
2021-09-25 17:47:05 +02:00
// Read the .env file
dotenv.config()
2021-09-25 12:11:27 +02:00
2021-11-04 20:06:51 +01:00
if (process.env.DOWNLOAD_FILES === "enabled")
2021-11-04 19:47:40 +01:00
await downloadEssentialData()
dbInit()
generateDB()
2021-10-30 21:39:21 +02:00
const Server = express()
njk.configure(
'views',
{
autoescape: true,
express: Server,
lstripBlocks: true,
trimBlocks: true
}
)
Server.use('/', routes)
2021-11-04 19:47:40 +01:00
Server.use('/api', api)
2021-10-30 21:39:21 +02:00
Server.use('/assets', express.static('static'))
2021-11-04 16:19:18 +01:00
Server.listen(process.env.PORT ?? 12345, () => log(`Server started and listening on port ${process.env.PORT}.`))