-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
54 lines (45 loc) · 1.4 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
// Dependencies
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const logger = require('morgan');
const socketio = require('socket.io');
const dotenv = require('dotenv');
const homeRoute = require('./api/routes/homeRoute');
const groupRoute = require('./apiv2/routes/groupRoute');
const userRoute = require('./apiv2/routes/userRoute');
const postRoute = require('./apiv2/routes/postRoute');
const rt = require('./socket');
// Load .env variables
dotenv.load();
// define PORT
const PORT = process.env.PORT || 3000;
// Connect to Database
mongoose.connect(process.env.DATABASE_URI);
// Use Logger
app.use(logger('dev'));
// Use Body Parser
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
// Use Routes
app.use('/', homeRoute);
app.use('/post', postRoute);
// app.use('/college', collegeRoute);
// app.use('/student', studentRoute);
// app.use('/staff', staffRoute);
// app.use('/class', classRoute);
// app.use('/department', departmentRoute);
app.use('/user', userRoute);
app.use('/group', groupRoute);
//Config WebSockets;
let server = require('http').Server(app);
let io = socketio(server);
io.on('connection', (socket) => {
rt.realTimePost(io, socket);
// rt.realTimeTest(io, socket);
})
// Listen for http requests;
server.listen(PORT, () => {
console.log(`Server is LIVE at :${PORT}`);
});