50 lines
1.2 KiB
JavaScript
50 lines
1.2 KiB
JavaScript
/**
|
|
* This is the entrypoint for 'DDStats'.
|
|
* DDStats is a custom API that servers statistics from the DDRace Network-
|
|
* @author BurnyLlama <xmpp:burnyllama@qwik.space>
|
|
*/
|
|
|
|
import express from 'express'
|
|
import dotenv from 'dotenv'
|
|
import njk from 'nunjucks'
|
|
|
|
import initLog from './libs/utils/log.js'
|
|
import routes from './routes/routes.js'
|
|
|
|
import { generateDB } from './libs/database/generate.js'
|
|
import { dbInit } from './libs/database/init.js'
|
|
import { downloadEssentialData } from './libs/download/dowload.js'
|
|
|
|
const start = Date.now()
|
|
const log = initLog("[ MAIN ]")
|
|
|
|
// Read the .env file
|
|
dotenv.config()
|
|
|
|
if (process.env.DOWNLOAD_FILES === "enabled")
|
|
await downloadEssentialData()
|
|
|
|
dbInit()
|
|
generateDB()
|
|
|
|
const Server = express()
|
|
|
|
njk.configure(
|
|
'views',
|
|
{
|
|
autoescape: true,
|
|
express: Server,
|
|
lstripBlocks: true,
|
|
trimBlocks: true
|
|
}
|
|
)
|
|
|
|
Server.use('/', routes)
|
|
Server.use('/api', routes)
|
|
Server.use('/assets', express.static('static'))
|
|
|
|
const elapsed = Date.now() - start
|
|
log(`Took ${elapsed/1000} seconds to start the server!`)
|
|
|
|
Server.listen(process.env.PORT ?? 12345, () => log(`Server started and listening on port ${process.env.PORT}.`))
|