-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
120 lines (94 loc) · 2.75 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
* Module dependencies.
*/
var express = require('express'),
async = require('async'),
Model = require('LazyBoy');
var app = module.exports = express.createServer();
// Configuration
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.compiler({ src: __dirname + '/public', enable: ['sass'] }));
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
app.configure('development', function(){
console.log("development");
Model.create_connection("jsinsa");
Model.load('models');
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('production', function() {
console.log("production");
Model.create_connection({
url: 'https://garrensmith.cloudant.com',
port: '443',
db:'jsinsa_prod',
auth: {
username: 'deesecendetumandereendle',
password: 'g4wS4ojqVrHQPaIES8u2yLHu'
},
secure:true,
});
Model.load('models');
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
// app.use(express.errorHandler());
});
// Routes
app.get('/seed_me', function(req,res) {
require('./seeds')();
res.send("seeding");
});
app.get('/', function(req, res){
async.parallel({
sessions: function(callback){
console.log("session");
var Session = Model('Session');
Session.view('allByTime',function (err, sessions) {
sessions.forEach(function (item) {
item.start_time = new Date(item.start_time).toUTCString();
item.end_time = new Date(item.end_time).toUTCString();
if (!item.questions) {
item.questions = [];
}
});
console.log("result");
callback(err, sessions);
});
},
comments: function(callback) {
var Comment = Model('Comment');
Comment.all(function (err, comments) {
callback(err, comments);
})
}
},
function(err, results) {
if (err) {
console.log("error");
console.dir(err);
};
console.log("result");
var mapped = results.sessions.map(function (item) {
return item.serialise();
});
console.log("rendering");
//console.dir(mapped);
res.render('index', { sessions: results.sessions, mapped: mapped, comments: results.comments});
});
});
app.post('/comment',function (req, res) {
console.log(req.body);
console.log(req.params);
var comment = req.body.comment;
Comment = Model('Comment');
Comment.create({name: comment.name, msg: comment.msg}).save();
res.send({response:"ok"});
});
var port = process.env.PORT || 3001;
app.listen(port, function() {
console.log("Listening on " + port);
});