-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
51 lines (44 loc) · 1.24 KB
/
server.js
File metadata and controls
51 lines (44 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require("dotenv").config();
const { sequelize } = require("./src/api/v1/database/models");
const express = require("express");
const cors = require("cors");
const morgan = require("morgan");
const AppRoutes = require("./src/api/v1/routes");
const app = express();
const cron = require("node-cron");
app.use(cors({ origin: "*" }));
app.use(express.json({ limit: "50mb" }));
app.use(express.urlencoded({ extended: true, limit: "50mb" }));
app.use(morgan("common"));
app.use("/api/v1", AppRoutes);
async function handle_cron() {
try {
/// check for due stream
} catch (error) {}
}
// Schedule the cron job for 12 AM UTC every day
cron.schedule(
"0 0 * * *",
async () => {
await handle_cron();
},
{
timezone: "UTC", // Ensure the timezone is set to UTC
}
);
app.get("/", async (req, res) => {
res.status(200).json({
success: true,
message: "Server is runnning successfully",
});
});
const ErrorHandler = require("./src/api/v1/validations/error/ErrorHandler");
app.use(ErrorHandler);
const server = app;
const PORT = process.env.PORT || 5000;
server.listen(PORT, async () => {
console.log("server running");
// await sequelize.sync();
await sequelize.authenticate({ force: true });
console.log("database connected");
});