ddstats-server/routes/routes.js

46 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-10-30 21:39:21 +02:00
import { Router } from 'express'
2021-11-04 22:50:57 +01:00
import wrapper from '../libs/database/wrapper.js'
import tx from '../libs/routex.js'
2021-11-05 21:04:53 +01:00
import { getStats } from '../libs/serverStats.js'
2021-10-30 21:39:21 +02:00
const routes = Router()
routes.get(
'/',
(req, res) => {
2021-11-04 22:50:57 +01:00
tx(req, res)('pages/landing.njk', null, { currentSection: null })
}
)
routes.get(
'/maps',
(req, res) => {
const maps = wrapper.allMaps()
tx(req, res)('pages/maps.njk', { maps }, true, { currentSection: "maps" })
2021-11-04 22:50:57 +01:00
}
)
routes.get(
'/maps/:map',
(req, res) => {
const map = wrapper.map(req.params.map)
const graphMap = wrapper.graphMap(req.params.map)
2021-11-04 23:20:41 +01:00
const raceLeaderboard = wrapper.leaderboardRace(req.params.map, 1, 10)
const teamLeaderboard = wrapper.leaderboardTeamrace(req.params.map, 1, 10)
const [success, error] = map ? [true, "No error!"] : [false, "Map not found!"]
tx(req, res)('pages/mapSingle.njk', { map, graphMap, raceLeaderboard, teamLeaderboard, error }, success, { currentSection: "maps" })
}
2021-10-30 21:39:21 +02:00
)
2021-11-05 21:04:53 +01:00
routes.get(
'/status',
(req, res) => {
const stats = getStats()
tx(req, res)('pages/stats.njk', { stats }, true, { currentSection: null })
}
)
2021-10-30 21:39:21 +02:00
export default routes