-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.js
44 lines (31 loc) · 866 Bytes
/
gui.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
// Routes for the gui
var express = require('express');
var app = express();
var router = express.Router();
require('node-jsx').install();
var React = require('react');
// pass the handler for the petitions
// so we use just one instance
module.exports = function(handler) {
router.get('/', function(req, res, next) {
handler.getLatestPetitions(10, function(err, resp) {
if (err) {
return next(err);
}
res.send(resp);
res.end();
});
});
router.get('/:id', function(req, res, next) {
handler.getPetitionById(req.params.id, function(err, resp) {
if (err) {
return next(err);
}
var petitionView = require('../src/views/petition.jsx');
var petition = resp._source;
res.send(React.renderToString(petitionView(petition)));
res.end();
})
});
return router;
}