GIF89a
import express from "express";
import cors from "cors";
import { logManager } from "./middlewares/log_manager.js";
import { errorHandler } from "./middlewares/error_handler.js";
import cron from 'node-cron';
import {
generateUserHistory,
resetHistoryData,
// resetAllBazaarGameTimings,
resetWebTimingAndResult,
resetEveryBazaarResults,
resetFinalAnk,
} from "./services/dataResetService.js";
const app = express();
app.use(cors({
origin: process.env.CORS_ORIGIN,
credentials: true
}));
/// Middlewares
app.use(express.json({ limit: "16mb" }));
app.use(express.urlencoded({ extended: true, limit: "16mb" }));
// app.use(express.static("public"));
app.use(express.static("../public/")); // uncomment for production
app.use(logManager);
/// Routes imports
import userRoutes from "./routes/userRoute.js";
import gameRoutes from "./routes/gameRoute.js";
import bidRoutes from "./routes/bidRoutes.js";
import transactionRoutes from "./routes/transRoute.js";
import settingRoutes from "./routes/settingRoute.js";
/// Routes
app.use('/api/v1/users/', userRoutes);
app.use('/api/v1/games/', gameRoutes);
app.use('/api/v1/bids/', bidRoutes);
app.use('/api/v1/settings/', settingRoutes);
app.use('/api/v1/transactions/', transactionRoutes);
app.get('/', function (req, res) {
res.send(`Server Running...`);
});
// Error handling middleware
app.use(errorHandler);
// Schedule the function to run at 12:30 am every day
cron.schedule('30 0 * * *', () => {
resetHistoryData();
generateUserHistory();
// resetAllBazaarGameTimings();
console.log(new Date());
console.log(`Now time : 12:30`);
}, {
scheduled: true,
timezone: "Asia/Kolkata"
}
);
// Schedule the function to run at 12:31 am every day
cron.schedule('0 1 * * *', () => {
resetFinalAnk();
resetWebTimingAndResult();
console.log(new Date());
console.log(`Now time : 01:00`);
}, {
scheduled: true,
timezone: "Asia/Kolkata"
});
// Schedule the function to run at 08:00 am every day
cron.schedule('0 8 * * *', () => {
resetEveryBazaarResults();
console.log(new Date());
console.log(`Now time : 08:00`);
}, {
scheduled: true,
timezone: "Asia/Kolkata"
});
// Schedule every 1 second
cron.schedule('*/1 * * * * *', () => {
// resetWebTimingAndResult();
// console.log(new Date());
// resetEveryBazaarResults();
// resetHistoryData();
// resetAllBazaarGameTimings();
// generateUserHistory();
});
// '*': Represents the minute (00:00 AM).
// '*': Represents the hour (00 AM).
// '*': Represents any day of the month.
// '*': Represents any month.
// '*': Represents any day of the week.
// INDIAN TIMEZONE
// {
// scheduled: true,
// timezone: "Asia/Kolkata"
// }
export { app }