const express = require('express'); const mongoose = require('mongoose'); const path = require('path'); const cors = require('cors'); const ejs = require('ejs'); const Statistics = require('./statistics') require('dotenv').config(); const app = express(); app.use(cors()); app.use(express.static(path.join(__dirname, 'public'))); app.get("/dashboard", async (req, res) => { try { const statistics = await Statistics.findOne({}); const html = await ejs.renderFile(path.join(__dirname, 'public', 'dashboard.ejs'), { statistics }); res.send(html); } catch (err) { console.error('Error fetching statistics:', err); res.status(500).send('Internal Server Error'); } }); app.get("/", (req, res) => { res.sendFile(path.join(__dirname, 'public', 'index.html')); }); app.get('*', (req, res) => { res.sendFile(path.join(__dirname, 'public', '404.html')); }); module.exports = app;