-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
79 lines (66 loc) · 1.86 KB
/
app.js
File metadata and controls
79 lines (66 loc) · 1.86 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
/** @format */
const express = require('express');
const http = require('http');
const PORT = process.env.PORT || 3002;
const mongoose = require('mongoose');
require('dotenv').config();
const socketio = require('socket.io');
const app = express();
const server = http.createServer(app);
const io = socketio(server, {
cors: {
origin: ['http://localhost:3000', 'http://localhost:3001', 'https://main--prodigy-path.netlify.app/', 'https://prodigy-path.netlify.app/', 'https://main--prodigy-path.netlify.app', 'https://prodigy-path.netlify.app'],
},
});
const userRouter = require('./routes/userRoutes');
const postRouter = require('./routes/postRoutes');
const taskRouter = require('./routes/taskRoutes');
const mentorProtegeRouter = require('./routes/mentorProtegeRoutes');
// const messageRouter = require('./routes/messageRoutes');
const cors = require('cors');
const startIo = require('./socket/server');
let DATABASE_URL;
if (process.env.NODE_ENV === 'test') {
DATABASE_URL = process.env.DATABASE_URL_TEST;
} else {
DATABASE_URL = process.env.DATABASE_URL_LIVE;
}
app.use(express.json());
app.use(cors());
mongoose.set('strictQuery', true);
async function connectToMongoDB() {
try {
await console.log(`Connected to MongoDB`);
await mongoose.connect(DATABASE_URL, {
useNewUrlParser: true,
bufferCommands: false,
});
} catch (error) {
console.error(error);
}
}
connectToMongoDB();
app.use(mentorProtegeRouter);
app.use(taskRouter);
app.use(userRouter);
app.use(postRouter);
// app.use(messageRouter);
startIo(io);
app.all('/', (req, res, next) => {
res.send('Proof Of Life4');
});
app.all('*', (req, res) => {
res.status(404).send({ message: 'Route not found' });
});
const start = () => {
server.listen(PORT, () => {
console.log(`running on ${PORT}`);
});
};
module.exports = {
startIo,
io,
start,
connectToMongoDB,
server,
};