-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmap.js
33 lines (30 loc) · 994 Bytes
/
map.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
module.exports = function(){
var express = require('express');
var router = express.Router();
function getParks(res, mysql, context, complete){
mysql.pool.query("SELECT parks.id as id, parks.name as name, parks.main_state as state,parks.region as region, parks.link as link\
FROM parks ORDER BY parks.name;", function(error, results, fields){
if(error){
res.write(JSON.stringify(error));
res.end();
}
context.parks = results;
complete();
});
}
//display page
router.get('/', function(req, res){
var callbackCount = 0;
var context = {};
context.jsscripts = [""];
var mysql = req.app.get('mysql');
getParks(res, mysql, context, complete);
function complete(){
callbackCount++;
if(callbackCount >= 1){
res.render('map', context);
}
}
});
return router;
}();