-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathserver.js
97 lines (74 loc) · 3.11 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
var express = require('express'),
cors = require('cors'),
marqdown = require('./marqdown.js'),
//routes = require('./routes/designer.js'),
//votes = require('./routes/live.js'),
//upload = require('./routes/upload.js'),
/*create = require('./routes/create.js'),
study = require('./routes/study.js'),
admin = require('./routes/admin.js');
*/
create = require('./mock_routes/create.js'),
study = require('./mock_routes/study.js'),
admin = require('./mock_routes/admin.js');
var app = express();
app.configure(function () {
app.use(express.logger('dev')); /* 'default', 'short', 'tiny', 'dev' */
app.use(express.bodyParser());
});
var whitelist = ['http://chrisparnin.me', 'http://pythontutor.com', 'http://happyface.io', 'http://happyface.io:8003', 'http://happyface.io/hf.html'];
var corsOptions = {
origin: function(origin, callback){
var originIsWhitelisted = whitelist.indexOf(origin) !== -1;
callback(null, originIsWhitelisted);
}
};
app.options('/api/study/vote/submit/', cors(corsOptions));
app.post('/api/design/survey',
function(req,res)
{
console.log(req.body.markdown);
//var text = marqdown.render( req.query.markdown );
var text = marqdown.render( req.body.markdown );
res.send( {preview: text} );
}
);
//app.get('/api/design/survey/all', routes.findAll );
//app.get('/api/design/survey/:id', routes.findById );
//app.get('/api/design/survey/admin/:token', routes.findByToken );
//app.post('/api/design/survey/save', routes.saveSurvey );
//app.post('/api/design/survey/open/', routes.openSurvey );
//app.post('/api/design/survey/close/', routes.closeSurvey );
//app.post('/api/design/survey/notify/', routes.notifyParticipant );
//// ################################
//// Towards general study management.
app.get('/api/study/load/:id', study.loadStudy );
app.get('/api/study/vote/status', study.voteStatus );
app.get('/api/study/status/:id', study.status );
app.get('/api/study/listing', study.listing );
app.post('/api/study/create', create.createStudy );
app.post('/api/study/vote/submit/', cors(corsOptions), study.submitVote );
//// ADMIN ROUTES
app.get('/api/study/admin/:token', admin.loadStudy );
app.get('/api/study/admin/download/:token', admin.download );
app.get('/api/study/admin/assign/:token', admin.assignWinner);
app.post('/api/study/admin/open/', admin.openStudy );
app.post('/api/study/admin/close/', admin.closeStudy );
app.post('/api/study/admin/notify/', admin.notifyParticipant);
//// ################################
//app.post('/api/upload', upload.uploadFile );
// survey listing for studies.
//app.get('/api/design/survey/all/listing', routes.studyListing );
// Download
//app.get('/api/design/survey/vote/download/:token', votes.download );
// Winner
//app.get('/api/design/survey/winner/:token', votes.pickParticipant );
// Voting
//app.get('/api/design/survey/vote/all', votes.findAll );
//app.post('/api/design/survey/vote/cast', votes.castVote );
//app.get('/api/design/survey/vote/status', votes.status );
//app.get('/api/design/survey/vote/stat/:id', votes.getSurveyStats );
var server = app.listen(process.env.MONGO_PORT);
console.log('Listening on port 3002...');
//server.close();
exports.server = server;