-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
78 lines (65 loc) · 2.05 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
// Note: classes are called "courses" on the backend
// JS libraries
let express = require('express');
let app = express();
let session = require('express-session');
let bodyParser = require('body-parser');
let uuid = require('uuid/v1');
let mongoose = require('mongoose');
// Set the root directory to client folder to find images etc
app.use(express.static(__dirname + '/client'));
// Database config
mongoose.Promise = global.Promise
mongoose.connect('mongodb://localhost:27017/classroomcompanion', {
useUnifiedTopology: true,
useNewUrlParser: true
},
function (error) {
if (error) {
return console.error('Unable to connect:', error);
}
});
mongoose.set('useCreateIndex', true);
// Middleware
app.use(express.static('public'));
app.use(bodyParser.urlencoded({
limit: '100mb', // Limiting for uploading pptx slides
extended: true,
}));
// Configure Pug templating
app.set('views', __dirname + '/views');
app.set('view engine', 'pug');
// Configure sessions
app.use(session({
genid: function (request) {
return uuid();
},
resave: false,
saveUninitialized: false,
secret: 'ssbu discord equator amdradeonr9'
}));
/**************** Routes ****************/
const userRouter = require('./routes/user.js');
const courseRouter = require('./routes/course.js');
const presentationRouter = require('./routes/presentation.js');
app.use(userRouter);
app.use(courseRouter);
app.use(presentationRouter);
/**************** GroupMaker Page ****************/
app.get('/groupMaker', function (request, response) {
// User not logged in redirect them
if (!request.session.username) { response.redirect("/"); }
response.render('groupMaker', {
title: 'Group Maker'
});
});
/**************** Logout Page ****************/
app.get('/logout', function (request, response) {
request.session.username = '';
response.redirect('/');
});
// Web listener
app.set('port', process.env.PORT || 3000);
app.listen(app.get('port'), function () {
console.log('ClassroomCompanion Server listening on port ' + app.get('port'));
});