import cors from "cors";
import express from "express";

import todosRoutes from "./routes/todos/todos.routes";
import authRoutes from "./routes/auth/auth.routes";
import usersRoutes from "./routes/users/users.routes";
import searchRoutes from "./routes/search/search.routes";

const app = express();
const port = process.env.PORT || 5000;

app.use(
  cors({
    origin: true,
    methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
    allowedHeaders: ["Content-Type", "Authorization"],
    credentials: true,
  })
);


app.use(express.json());

app.use("/api/auth", authRoutes);
app.use("/api/todos", todosRoutes);
app.use("/api/users", usersRoutes);
app.use("/api/search", searchRoutes);

app.listen(port, () => {
  console.log(`Server started on port ${port}`);
});
