NoLev commited on
Commit
76ba035
·
verified ·
1 Parent(s): 7c52517

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +19 -4
server.js CHANGED
@@ -2,6 +2,7 @@ const express = require('express');
2
  const session = require('express-session');
3
  const path = require('path');
4
  const multer = require('multer');
 
5
  const authRoutes = require('./routes/auth');
6
  const adminRoutes = require('./routes/admin');
7
  const userRoutes = require('./routes/user');
@@ -46,9 +47,23 @@ app.use('/user/kyc', upload.fields([
46
  console.log('Multer middleware configured');
47
 
48
  // Root route
49
- app.get('/', (req, res) => {
50
- console.log('Serving root route');
51
- res.render('index', { title: 'HYIP Platform' });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  });
53
 
54
  // Routes
@@ -62,7 +77,7 @@ console.log('Routes configured');
62
  app.get('/admin/kyc-document/:id', async (req, res) => {
63
  try {
64
  console.log(`Serving KYC document ID: ${req.params.id}`);
65
- const [doc] = await require('./config/db').query('SELECT file_path FROM kyc_documents WHERE id = ?', [req.params.id]);
66
  if (!doc.length) return res.status(404).send('Document not found');
67
  res.sendFile(path.resolve(doc[0].file_path));
68
  } catch (error) {
 
2
  const session = require('express-session');
3
  const path = require('path');
4
  const multer = require('multer');
5
+ const pool = require('./config/db');
6
  const authRoutes = require('./routes/auth');
7
  const adminRoutes = require('./routes/admin');
8
  const userRoutes = require('./routes/user');
 
47
  console.log('Multer middleware configured');
48
 
49
  // Root route
50
+ app.get('/', async (req, res) => {
51
+ try {
52
+ console.log('Serving root route');
53
+ const [testimonials] = await pool.query('SELECT * FROM testimonials WHERE status = ? LIMIT 3', ['approved']);
54
+ const [withdrawals] = await pool.query(`
55
+ SELECT w.*, u.username
56
+ FROM withdrawals w
57
+ JOIN users u ON w.user_id = u.id
58
+ WHERE w.status = ?
59
+ ORDER BY w.created_at DESC
60
+ LIMIT 5
61
+ `, ['approved']);
62
+ res.render('index', { title: 'HYIP Platform', testimonials, withdrawals });
63
+ } catch (error) {
64
+ console.error('Error fetching root data:', error);
65
+ res.status(500).send('Error loading homepage');
66
+ }
67
  });
68
 
69
  // Routes
 
77
  app.get('/admin/kyc-document/:id', async (req, res) => {
78
  try {
79
  console.log(`Serving KYC document ID: ${req.params.id}`);
80
+ const [doc] = await pool.query('SELECT file_path FROM kyc_documents WHERE id = ?', [req.params.id]);
81
  if (!doc.length) return res.status(404).send('Document not found');
82
  res.sendFile(path.resolve(doc[0].file_path));
83
  } catch (error) {