-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.js
56 lines (46 loc) · 1.34 KB
/
api.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
var express = require('express');
var app = express();
var databaseUrl = 'root:[email protected]:41022/POIDB'; // "username:[email protected]/mydb"
//var databaseUrl = 'localhost/POIDB'; // "username:[email protected]/mydb"
var collections = ['pois', 'poiTypes'];
var db = require('mongojs').connect(databaseUrl, collections);
//Get the different poi-types
app.get('/types', function(req, res){
'use strict';
db.poiTypes.find({}, {Name: 1}, function(err, data){
res.send(data);
});
});
//Get pois by type(category)
app.get('/pois/:type', function(req, res){
'use strict';
var type = req.params.type;
db.pois.find({POIType: type}, function(err, data){
res.send(200, data);
});
});
//Get all data
app.get('/pois', function(req, res){
'use strict';
var query = req.query;
console.log(query);
db.pois.find(query, function(err, data){
res.send(200, data);
});
});
//Search all pois
app.get('/search', function(req, res){
'use strict';
var query = req.query;
db.pois.find({'Name': new RegExp(query.query, 'i')}, function(err, data){
res.send(200, data);
console.log(err);
console.log(data);
});
});
//Not found 404 error stuff
app.get('*', function(req, res){
'use strict';
res.sendfile('error/404.html');
});
app.listen(8087);