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'
|
|
|
|
|
2021-09-29 20:29:06 +02:00
|
|
|
import sqlite2mongo from './libs/database/sqlite2mongo.js'
|
|
|
|
import databaseInit from './libs/database/init.js'
|
2021-10-13 16:40:18 +02:00
|
|
|
import initLog from './libs/utils/log.js'
|
2021-10-30 21:39:21 +02:00
|
|
|
|
2021-10-03 19:00:41 +02:00
|
|
|
import api from './api/api.js'
|
2021-10-30 21:39:21 +02:00
|
|
|
import routes from './routes/routes.js'
|
|
|
|
|
2021-10-16 19:11:16 +02:00
|
|
|
import { initWorkers } from './libs/utils/multithread.js'
|
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-10-30 21:39:21 +02:00
|
|
|
// await databaseInit()
|
2021-10-03 19:00:41 +02:00
|
|
|
|
2021-10-16 19:11:16 +02:00
|
|
|
initWorkers(process.env.THREADS ?? 4)
|
|
|
|
|
2021-10-03 19:00:41 +02:00
|
|
|
if (process.env.LOAD_DB === "true")
|
|
|
|
await sqlite2mongo()
|
2021-09-25 17:47:05 +02:00
|
|
|
|
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)
|
|
|
|
Server.use('/assets', express.static('static'))
|
|
|
|
Server.use('/api', api)
|
|
|
|
|
2021-10-16 19:11:16 +02:00
|
|
|
Server.listen(process.env.PORT ?? 12345, () => log(`Server started and listening on port ${process.env.PORT}.`))
|