require("dotenv").config();
const express=require("express");
const app=express();
const cors=require("cors")
const port=process.env.PORT || 5000;
const db=require("./config/db");
const Authrouter = require("./routes/Authrouter");
const Adminrouter = require("./routes/Adminrouter");

app.use(express.json())
app.use(express.static("public"))
app.use(express.urlencoded({extended:true}))
app.use(
  cors({
    origin: [
      "http://localhost:5173",
      "http://localhost:5174",
      "https://allcareacademy.com",
      "*",
    ],
    methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
    allowedHeaders: [
      "Content-Type",
      "Authorization",
      "x-api-key",
      "x-merchant-id",
      "x-timestamp",
      "x-nonce",
      "x-sign",
      "Access-Control-Allow-Origin",
    ],
    credentials: true,
    optionsSuccessStatus: 200,
  })
);
db();

app.use("/api/auth",Authrouter);
app.use("/api/admin",Adminrouter)
app.get("/",(req,res)=>{
    try {
        res.send("Hello shihab")
    } catch (error) {
        console.log(error)
    }
})

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