-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
54 lines (39 loc) · 1.31 KB
/
app.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
var express = require('express');
var path = require('path');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
var http = require('http');
var io = require('socket.io');
var {socketConnection, socketJwtVerification} = require('./socketControllers');
require('dotenv/config');
var app = express();
var server = http.Server(app);
var io = io(server);
//MiddleWares
//(things that every request go through, for exapmle a function with req, res and next params)
app.use(bodyParser.json());
//Mongoose connection
mongoose.connect(
process.env.DB_CONNECTION_URL,
{useNewUrlParser: true, useUnifiedTopology: true},
() => {
console.log('Successfully connected to MongoDB!');
});
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'MongoDB connection error: '));
//Routes
const postsRoute = require('./routes/posts');
const indexRoute = require('./routes/index');
const authRoute = require('./routes/auth');
const roomRoute = require('./routes/rooms');
app.use('/', indexRoute);
app.use('/posts', postsRoute);
app.use('/auth', authRoute);
app.use('/rooms', roomRoute);
//Setting up the socket connection
socketJwtVerification(io);
socketConnection(io);
//Server listening
server.listen(process.env.PORT, () => {
console.log('Listening at port ' + process.env.PORT);
});