-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
139 lines (107 loc) · 3.82 KB
/
index.js
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
const express = require('express');
const multer = require('multer');
const logger = require('morgan');
const createEroor = require('http-errors');
const mongoose = require('mongoose');
const config = require('./database/dbConfig.json');
const cors = require('cors');
const path = require('path');
const http = require('http');
const { createAdminUserIfNotExists } = require('./routes/DataInitializer');
require("dotenv").config();
const app = express();
app.use(cors(config.cors.options));
const storage = multer.diskStorage({
destination: function(req, file, cb) {
cb(null, 'uploads/');
},
filename: function(req, file, cb) {
cb(null, Date.now() + path.extname(file.originalname));
}
});
const upload = multer({ storage: storage });
app.post('/upload', upload.single('image'), (req, res) => {
res.json({ imageUrl: '/uploads/' + req.file.filename });
});
const PORT = process.env.PORT || 3000;
const { Server } = require("socket.io");
const server = http.createServer(app);
const io = new Server(server, {
cors: {
origin: "https://main--idyllic-malabi-e8aa4a.netlify.app",
methods: ["GET", "POST"],
},
});
io.on('connection', (socket) => {
socket.on('message', (message) => {
console.log('Message received:', message);
// Broadcast the message to all connected clients
io.emit('message', message);
});
socket.on('disconnect', () => {
});
});
const connectDB = require("./connectMongo");
connectDB();
app.use('/uploads', express.static(path.join(__dirname, 'uploads')));
app.use(express.json())
const courseRouter = require('./routes/courseRoute');
const classroomRouter = require('./routes/classroomRoute');
const examRouter = require('./routes/examRoute');
const sessionRouter = require('./routes/sessionRoute');
const usersRouter = require('./routes/userroutes');
const locationRouter = require('./routes/locationRouter');
const eventRouter = require('./routes/eventRoute');
const bookRouter = require('./routes/bookRoute')
const paymentRouter = require('./routes/payementRoute')
const messageRouter = require('./routes/messageRoute')
const transactionRouter = require('./routes/transactionRoute')
const noteRouter = require('./routes/noteRoute');
const commentaireRouter = require('./routes/commentaireRoute');
const obserRouter = require('./routes/observationRoute');
const {cronFiltrageCollaboratif, cronBaseSurLeContenu} = require('./shared/cron');
app.use('/users', usersRouter)
const productRouter = require('./routes/productRoute')
app.use('/images', express.static('uploads/coursesImages'));
app.use(express.json());
const orderRouter = require('./routes/orderRoute')
app.use(cors());
app.use(express.json())
//gestion cours
app.use('/courses', courseRouter);
app.use('/classrooms', classroomRouter);
app.use('/exams', examRouter);
app.use('/sessions', sessionRouter);
app.use('/locations', locationRouter);
app.use('/commentaires', commentaireRouter);
app.use('/observations', obserRouter);
//gestion magasin
app.use('/market',productRouter)
app.use('/uploads', express.static('uploads'));
app.use('/orders', orderRouter);
app.use('/payement',paymentRouter);
app.use('/api/messages', messageRouter);
app.use('/transaction', transactionRouter);
app.use('/notes', noteRouter);
cronFiltrageCollaboratif();
cronBaseSurLeContenu();
app.use((req, res, next) => {
console.log(`${req.method} request for '${req.url}'`);
next();
});
//gestion evenements
app.use('/events', eventRouter);
app.use('/book',bookRouter);
app.get('/', (req, res) => {
res.send('Hello, Express!');
});
const reclamationrouter = require('./routes/reclamationRoutes')
app.use('/Reclamtions', reclamationrouter(io))
mongoose.connect(config.mongo.uri,
console.info('Database connected successfully')
);
// Start the server
server.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
module.exports = { app, server };