1
0
mirror of https://dev.s-ul.net/Galexion/MaiMaiDXNet.git synced 2024-12-18 11:05:54 +01:00
MaiMaiDXNet/routes/index.js

39 lines
1.1 KiB
JavaScript
Raw Normal View History

2023-02-17 00:50:32 +01:00
var express = require('express');
var router = express.Router();
var fetch = require('cross-fetch');
2023-05-07 07:20:04 +02:00
var config = require('../config.json');
var { getUserCount, getUserData } = require("../dbhandler.js");
2023-02-17 00:50:32 +01:00
/* GET home page. */
var title = 'MaiDXNet';
router.get('/', async function (req, res, next) {
2023-07-17 04:54:56 +02:00
await getUserCount().then(
(userCount) => {
2023-02-17 00:50:32 +01:00
var params = {
2023-07-17 04:54:56 +02:00
totalUsers: userCount, // ToDo: Change this to use the internal dbhandler api
serverType: config.serverType
};
2023-07-17 04:54:56 +02:00
console.log(`Recived User Count:`+userCount);
res.render('index', { title: title, params: params });
},
(reason) => {
res.render('error', { title: title, error: reason });
console.error(reason); // Error!
},
);
});
router.get('/user', async function (req, res, next) {
try {
const cookies = req.cookies
console.log(cookies)
if (cookies.aime_card_id === undefined) {
return res.redirect("/")
}
res.render('user', { title: title, userdata: await getUserData(req) });
} catch (err) {
res.render('error', { error: err });
}
});
module.exports = router;