Skip to content

Commit ff82224

Browse files
committed
add router for gui and api
1 parent 4646d8f commit ff82224

File tree

4 files changed

+83
-37
lines changed

4 files changed

+83
-37
lines changed

index.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@ var express = require('express');
22

33
var app = express();
44

5-
// home middleware
6-
app.get('/', function (req, res) {
7-
res.send('E-Action Middleware')
8-
})
9-
10-
11-
// use a router for petitions
12-
var petitions = require('./routes/petitions');
13-
app.use('/petitions', petitions);
5+
// the petitions handler
6+
var petitions = require('./src/petitions')({
7+
host: "localhost:9200",
8+
indexName: "e-actions-test",
9+
typeName: "petitions"
10+
});
11+
12+
// the app
13+
var gui = require('./routes/gui')(petitions);
14+
app.use('/', gui);
15+
16+
// the api
17+
var petitions = require('./routes/petitions')(petitions);
18+
app.use('/api/petitions', petitions);
1419

1520
// start the server
1621
var server = app.listen(3000, function() {

routes/gui.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Routes for the gui
2+
var express = require('express');
3+
4+
var app = express();
5+
var router = express.Router();
6+
7+
// pass the handler for the petitions
8+
// so we use just one instance
9+
module.exports = function(handler) {
10+
11+
router.get('/', function(req, res, next) {
12+
handler.getLatestPetitions(10, function(err, resp) {
13+
if (err) {
14+
return next(err);
15+
}
16+
17+
res.send(resp);
18+
res.end();
19+
20+
});
21+
});
22+
23+
router.get('/:id', function(req, res, next) {
24+
handler.getPetitionById(req.params.id, function(err, resp) {
25+
if (err) {
26+
return next(err);
27+
}
28+
29+
res.send(resp);
30+
res.end();
31+
32+
})
33+
});
34+
35+
return router;
36+
37+
}

routes/petitions.js

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,35 @@ var router = express.Router();
66

77
var handler = require('../src/petitions');
88

9-
// list all the petitions
10-
router.get('/', function(req, res, next) {
11-
throw new Error('not implemented');
12-
});
13-
14-
// return a petition
15-
router.get('/:id', function(req, res, next) {
16-
throw new Error('not implemented');
17-
});
18-
19-
// create a petition
20-
router.post('/', function(req, res, next) {
21-
throw new Error('not implemented');
22-
});
23-
24-
// update a petition
25-
router.put('/:id', function(req, res, next) {
26-
throw new Error('not implemented');
27-
});
28-
29-
// delete a petition
30-
router.delete('/:id', function (req, res, next) {
31-
throw new Error('not implemented');
32-
});
33-
34-
module.exports = router;
9+
module.exports = function(handler) {
10+
11+
// list all the petitions
12+
router.get('/', function(req, res, next) {
13+
throw new Error('not implemented');
14+
});
15+
16+
// return a petition
17+
router.get('/:id', function(req, res, next) {
18+
throw new Error('not implemented');
19+
});
20+
21+
// create a petition
22+
router.post('/', function(req, res, next) {
23+
throw new Error('not implemented');
24+
});
25+
26+
// update a petition
27+
router.put('/:id', function(req, res, next) {
28+
throw new Error('not implemented');
29+
});
30+
31+
// delete a petition
32+
router.delete('/:id', function (req, res, next) {
33+
throw new Error('not implemented');
34+
});
35+
36+
return router;
37+
38+
}
39+
40+

src/petitions.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ var _ = require('lodash');
55

66
module.exports = function Petitions(options) {
77

8-
9-
108
var client = new elasticsearch.Client({
119
host: options.host,
1210
log: 'error'

0 commit comments

Comments
 (0)