Update server.js
Browse files
server.js
CHANGED
|
@@ -2,7 +2,7 @@ const express = require('express');
|
|
| 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');
|
|
@@ -12,6 +12,13 @@ const app = express();
|
|
| 12 |
|
| 13 |
console.log('Starting server...');
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
// Set view engine
|
| 16 |
app.set('view engine', 'ejs');
|
| 17 |
app.set('views', path.join(__dirname, 'public/views'));
|
|
@@ -50,7 +57,7 @@ console.log('Multer middleware configured');
|
|
| 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
|
|
@@ -58,11 +65,11 @@ app.get('/', async (req, res) => {
|
|
| 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.
|
| 66 |
}
|
| 67 |
});
|
| 68 |
|
|
|
|
| 2 |
const session = require('express-session');
|
| 3 |
const path = require('path');
|
| 4 |
const multer = require('multer');
|
| 5 |
+
const { pool, initializeSchema } = require('./config/db');
|
| 6 |
const authRoutes = require('./routes/auth');
|
| 7 |
const adminRoutes = require('./routes/admin');
|
| 8 |
const userRoutes = require('./routes/user');
|
|
|
|
| 12 |
|
| 13 |
console.log('Starting server...');
|
| 14 |
|
| 15 |
+
// Initialize database schema
|
| 16 |
+
initializeSchema().then(() => {
|
| 17 |
+
console.log('Schema initialization completed');
|
| 18 |
+
}).catch(err => {
|
| 19 |
+
console.error('Failed to initialize schema:', err);
|
| 20 |
+
});
|
| 21 |
+
|
| 22 |
// Set view engine
|
| 23 |
app.set('view engine', 'ejs');
|
| 24 |
app.set('views', path.join(__dirname, 'public/views'));
|
|
|
|
| 57 |
app.get('/', async (req, res) => {
|
| 58 |
try {
|
| 59 |
console.log('Serving root route');
|
| 60 |
+
const [testimonials] = await pool.query('SELECT * FROM testimonials WHERE status = ? LIMIT 3', ['approved']).catch(() => [[]]);
|
| 61 |
const [withdrawals] = await pool.query(`
|
| 62 |
SELECT w.*, u.username
|
| 63 |
FROM withdrawals w
|
|
|
|
| 65 |
WHERE w.status = ?
|
| 66 |
ORDER BY w.created_at DESC
|
| 67 |
LIMIT 5
|
| 68 |
+
`, ['approved']).catch(() => [[]]);
|
| 69 |
+
res.render('index', { title: 'HYIP Platform', testimonials: testimonials || [], withdrawals: withdrawals || [] });
|
| 70 |
} catch (error) {
|
| 71 |
console.error('Error fetching root data:', error);
|
| 72 |
+
res.render('index', { title: 'HYIP Platform', testimonials: [], withdrawals: [] });
|
| 73 |
}
|
| 74 |
});
|
| 75 |
|