const express = require("express");
const http = require("http");
const cors = require("cors");
const path = require("path")

const app = express();
const server = http.createServer(app);
const PORT = 4030 || process.env.PORT;


app.use(cors());
app.use(express.json());

const connectDB = require("./db/config");

app.get("/", async (req, res) => {
    res.send("Sarbi Backend is Working!")
});

app.use("/api", require("./routes/user"));
app.use("/api", require("./routes/admin"));

app.use("/",
    express.static( path.resolve(__dirname, "./public/user/"))
);

const start = async () => {
    try {
        connectDB();
        server.listen(PORT, ()=> {
            console.log(`Server is Running on PORT: ${PORT}`);
        })
    } catch (error) {
        console.log("Having Errors While Running Server!", error);
    }
};

start();