-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
57 lines (47 loc) · 1.44 KB
/
server.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
require('dotenv').config();
const express = require('express');
const cors = require('cors');
const mongoose = require('mongoose');
const http = require('http');
const app = express();
const server = http.createServer(app);
const { Server } = require('socket.io');
const io = new Server(server, {
cors: {
origin: '*',
}
});
const PORT = process.env.PORT || 4000;
const registration = require('./routes/register');
const login = require('./routes/login');
const fetchMessages = require('./routes/fetchMessages');
const postMessages = require('./routes/postMessages');
const transporterList = require('./routes/fetchTransportersList');
const orderList = require('./routes/fetchOrderList');
const postOrderMessages = require('./routes/postOrderMessages');
const pay = require('./routes/pay');
app.use(cors());
app.use(express.json());
app.get('/', (req, res) => {
res.send('Server up and running');
});
app.use('/api/', (req, res, next) => {
req.io = io;
next();
}, login);
app.use('/api/', registration);
app.use('/api/', fetchMessages);
app.use('/api/', postMessages);
app.use('/api/', transporterList);
app.use('/api/', orderList);
app.use('/api/', postOrderMessages);
app.use('/api/', pay);
const mongo = async () => await mongoose.connect(process.env.MONGO_DB);
mongo().then(() => {
console.log('MongoDB Connected');
server.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
}).catch((err) => {
console.log(err);
});