-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
111 lines (99 loc) · 3.1 KB
/
server.js
File metadata and controls
111 lines (99 loc) · 3.1 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// APP Modules
require("dotenv").config();
const express = require("express");
const cron = require("node-cron");
const studentUtil = require("./utils/student");
const bodyParser = require("body-parser");
const cors = require("cors");
const { createServer } = require("http");
const { Server } = require("socket.io");
// App Config
const app = express();
const server = createServer(app);
app.use(
cors({
origin: [
"http://localhost:3000",
"http://localhost:3001",
"http://localhost:5173",
"https://board.ingelt.com",
"https://student.ingelt.com",
"https://teacher.ingelt.com",
"https://partner.ingelt.com",
"https://godseye.ingeltboard.com",
"https://student-staging-abcd-001-020-143.ingelt.com",
"https://ingeltboard.com",
"https://macverin.com",
"https://student-ingelt.toystack.dev",
"https://godseye.toystack.dev",
"https://godseye-ingelt.netlify.app"
],
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
allowedHeaders: 'Content-Type,Authorization,awskey',
credentials: true,
})
);
// Socket Config
exports.io = new Server(server, {
// To be used in socket/socket.js
cors: {
origin: [
"http://localhost:3000",
"http://localhost:3001",
"http://localhost:5173",
"https://student.ingelt.com",
"https://teacher.ingelt.com",
"https://partner.ingelt.com",
"https://godseye.ingeltboard.com",
"https://student-staging-abcd-001-020-143.ingelt.com",
"https://ingeltboard.com",
"https://student-ingelt.toystack.dev",
"https://godseye.toystack.dev",
"https://godseye-ingelt.netlify.app"
],
},
});
// Socket Functionality
require("./socket/socket");
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// Services Config
const ingeltServices = require("./services/ingelt");
const studentServices = require("./services/student");
const adminServices = require("./services/admin");
const teacherServices = require("./services/teacher");
app.use("/ingelt", ingeltServices);
app.use("/student", studentServices);
// Schedule the updateStudentStatus function to run every day at 00:00 (midnight)
cron.schedule("0 0 * * *", () => {
studentUtil.updateStudentStatus();
});
// cron.schedule('30 15 * * *', () => {
// console.log('Running updateStudentStatus...');
// studentUtil.updateStudentStatus();
// });
app.get('/', (req, res)=>{
res.send("server running")
})
app.use("/admin", adminServices);
app.use("/teacher", teacherServices);
// Auth Config
const auth = require("./auth");
app.use("/auth", auth);
// get images route
const image = require("./assets/getimage");
app.use("/images", image);
// mail service
const mailService = require("./mail");
app.use("/mail", mailService);
// DB and Server Config
const PORT = process.env.PORT || 8000;
const db = require("./models");
require("./models/associations");
// TODO: FORCE ALTER ONLY FOR DEV ENVIRONMENT { alter: true, force: true }
db.sequelize.sync({ alter: true }).then(() => {
// App Listen
server.listen(PORT, () => {
console.log(`🚀 Server is running on port ${PORT}`);
});
});