
const express = require("express");
const session = require("express-session");
const dotenv = require("dotenv");
const cors = require("cors");
const connectDB = require("./config/db");
const passport = require('passport');
const authController = require('./controllers/authcontrollers');
const path=require('path')
const passportConfig = require("./config/passport");

dotenv.config();
const app = express();
app.use(express.urlencoded({ extended: true }));
app.use('/webhook',require('./routes/webhookroute'));

// Middleware
app.use(cors());
app.use(express.json({ limit: "100mb" }));
app.use(express.urlencoded({ extended: true, limit: "100mb"}));
app.set('view engine', 'ejs');
// Set views directory
app.set('views', path.join(__dirname, 'views'));

// Serve static files (assets)
app.use(express.static(path.join(__dirname, 'assets')));
app.use(
  session({
    secret: "securitykey",
    resave: false,
    saveUninitialized: true,
    cookie: { maxAge: 1000 * 60 * 60 * 24, httpOnly: true }
  })
);

// Initialize passport
app.use(passport.initialize());
app.use(passport.session());

app.use('/uploads', express.static(path.join(__dirname, 'uploads')));
app.use('/zips',express.static(path.join(__dirname,'public/zips')))

// --- Simple Session Setup (no MongoStore) ---
require('./cron/croncheck')
// Routes
const DashRoutes = require("./routes/dashboardroutes");
app.use("/api", require('./routes/authroutes'));
app.use("/", DashRoutes);
app.use('/cron',require('./cron/cronroute'));
app.use("/api/webhooks", require("./routes/webhookroute"));

// Start server
const PORT = process.env.PORT;
app.listen(PORT, () => console.log(`Server running on port http://localhost:${PORT}`));
 