This repository has been archived by the owner on Jan 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
65 lines (53 loc) · 2.01 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
var express = require('express'),
Bookshelf = require('bookshelf'),
http = require('http'),
browserify = require('browserify-middleware'),
nunjucks = require('nunjucks'),
_ = require('underscore');
var app = express();
var conf = require('./config');
app.db = Bookshelf.initialize(conf.database);
app.models = require('./models')(app);
nunjucks.configure(__dirname + '/views', {
autoescape: true,
express : app
});
app.get('/application.js', browserify('./client/index.js', {transform: ['reactify']}));
app.use('/api', require('./api'));
app.get('/admin/:pass', function(req, res,next) {
if (process.env.NODE_ENV === 'production' && req.param('pass') !== process.env.ADMIN_KEY) return res.send(403);
var col = new req.app.models.Workshops();
var col2 = new req.app.models.ParticipantWorkshops();
col2.fetch({
withRelated: ['participant']
}).then(function(workshopParticipants) {
col.fetch().then(function(workshops) {
res.render('admin.html', {
workshops: workshops.toJSON().map(function(ws) {
var f = function(one) {
return one.get('workshop_id') == ws.id;
};
return _.extend({}, ws, {
participants: workshopParticipants.filter(f).map(function(one) {
return _.extend({}, one.toJSON(), {name: one.related('participant').get('name') });
})
});
})
});
}, next);
}, next);
});
app.get('/:hash', function(req, res, next) {
var hash = req.param('hash');
new app.models.Participant({hash: hash}).fetch().then(function(model) {
if (!model) return next();
res.render('app.html', model.toJSON());
}, next);
});
app.get('/', function(req, res) {
res.render('index.html');
});
var server = http.createServer(app);
server.listen(process.env.PORT || 1337, function() {
console.log('Listening on http://localhost:%d', server.address().port);
});