forked from azat-co/sfy-gallery
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
65 lines (55 loc) · 1.49 KB
/
Copy pathserver.js
File metadata and controls
65 lines (55 loc) · 1.49 KB
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
var express = require('express');
var superagent = require('superagent');
var consolidate = require('consolidate');
var apikey = require(__dirname + "/config.js").apikey;
var sunlight = require('./sunlight.js');
var url = require("url");
var _ = require("underscore");
var params;
var port = process.env.PORT || 3001;
var app = express();
//Configure template engine
app.engine('html', consolidate.handlebars);
app.set('view engine', 'html');
app.set('views', __dirname + '/views');
//Set up static folder
app.use(express.static(__dirname + '/public'));
//**Routes**
//Bills legislator voted on
app.get('/',function(req, res){
params = {
filter: 'history',
method: 'bills',
api_key: apikey
};
//Fetch elements from Sunlight API
sunlight.fetchActiveBills(params, function(data){
res.render('index', data);
});
});
//Legislator Bio
app.get('/:zip',function(req, res){
params = {
method: '/locate?zip=',
zip: req.params.zip,
api_key: apikey
};
//Fetch elements from Sunlight API
sunlight.fetchLegislators(params, function(data){
data = _.extend(data, params);
res.render('legislator', data);
});
});
//Bills legislator voted on
app.get('/legislator/:bioguide',function(req, res){
params = {
bioguide: req.params.bioguide,
api_key: apikey
};
//Fetch elements from Sunlight API
sunlight.fetchLegislatorVotes(params, function(data){
res.locals = {bioguide: params.bioguide};
res.render('legislatorPost', data);
});
});
app.listen(port);