const express = require("express");
const cors = require("cors");
const config = require("./config/config.js");
const connectDB = require("./db/db.js");
const authRoutes = require("./routes/authRoutes");
const userRoutes = require("./routes/userRoutes");
const serverRoutes = require("./routes/serverRoutes.js");
const app = express();

connectDB();

app.use(
  cors({
    origin: "*",
    allowedHeaders: ["Content-Type", "Authorization"],
    credentials: true,
  }),
);
app.use(express.json());
app.use(express.urlencoded({ extended: true }));

app.use("/api/auth", authRoutes);
app.use("/api/users", userRoutes);
app.use("/api/servers", serverRoutes);

app.get("/health", (req, res) => {
  res.status(200).json({ status: "OK" });
});

const PORT = config.port;
app.listen(PORT, () => {
  console.log(`🚀 Server running on port ${PORT}`);
});
