import express from "express"
import cors from "cors"
import dotenv from "dotenv"
import { prepareDb } from "./configs/db.js"
import cookieParser from "cookie-parser"
dotenv.config()

import authRoute from "./routes/auth.route.js"
import studentRoute from "./routes/student.route.js"
import courseRoute from "./routes/course.route.js"
import reportRoute from "./routes/report.route.js"

const app = express()
const port = process.env.PORT
app.use(cors({
    origin: "http://localhost:5173",
    credentials: true
}))
app.use(express.json())
app.use(cookieParser())

app.use("/api/auth", authRoute)
app.use("/api/students", studentRoute)
app.use("/api/courses", courseRoute)

app.use("/api/report", reportRoute)

app.listen(port, () => {
    console.log(`Server is running on port ${port}`)
    prepareDb()
})