-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
49 lines (36 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
var express = require('express');
var expressHandlebars = require('express3-handlebars');
var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
var expressSession = require('express-session');
var app = express();
var handlebars = require('./helpers/create_handlebars');
app.engine('handlebars', handlebars.engine);
app.set('view engine', 'handlebars');
app.use(bodyParser());
app.use(cookieParser());
app.use(expressSession({secret:'somesecretword'}));
var checkLogin = require('./middleware/check_login');
var requireLogin = require('./middleware/require_login');
app.use(checkLogin);
var weekData = require('./data/weeks');
app.get('/', function(req, res){
res.render('index', {
currentWeek: weekData.currentWeek()
});
});
var studentRoutes = require('./routes/students');
app.get('/students', studentRoutes.get);
var weeksRoutes = require('./routes/weeks');
app.get('/weeks', weeksRoutes.get);
app.get('/weeks/:weekNumber', weeksRoutes.weekNumber);
app.post('/attendance/:weekNumber', requireLogin, weeksRoutes.attendance);
var loginRoutes = require('./routes/login');
app.get('/login', loginRoutes.get);
app.post('/login', loginRoutes.post);
var logoutRoutes = require('./routes/logout');
app.get('/logout', logoutRoutes.get);
app.use('/public', express.static('public'));
var port = Number(process.env.PORT || 5000);
console.log('Listening on port',port);
app.listen(port);