require('dotenv').config();
const express = require('express');
const path = require('path');
const connectDB = require('./config/db');
const bookRoutes = require('./routes/bookRoutes');
const orderRoutes = require('./routes/orderRoutes'); // 1. Order yo'llarini chaqiramiz

const app = express();
connectDB();

app.use(express.json());
app.use(express.static(path.join(__dirname, 'public')));

// 2. Yo'nalishlarni (routes) ro'yxatdan o'tkazamiz
app.use('/api', bookRoutes); 
app.use('/api', orderRoutes); // 3. Endi /api/orders manzili ishlaydi

app.get('/', (req, res) => {
    res.sendFile(path.join(__dirname, 'public', 'index.html'));
});

const PORT = process.env.PORT || 5000;
app.listen(PORT, () => console.log(`Server running on http://localhost:${PORT}`));