-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.js
75 lines (73 loc) · 1.87 KB
/
routes.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
var requestn = require("request");
var server_config = require("./config/server").settings;
var async = require("async");
var csv = require("csv");
var _ = require("underscore");
var fs = require("fs");
var paths = [
{
method: "GET",
path: "/",
handler: function(request, reply){
reply.view("index", {
api: true
});
}
},
{
method: "GET",
path: "/api/v3/status/today",
handler: function(request, reply){
var object = {
name: "Todays Status",
path: "/api/v3/status/today"
};
requestn({
uri: "https://api.cityofnewyork.us/311/v1/municipalservices?app_id=" + server_config.nyc311id + "&app_key=" + server_config.nyc311key,
timeout: 100000
}, function(error, response, body){
if(!error && response.statusCode == 200 && JSON.parse(body).items[0].items !== undefined){
object.results = JSON.parse(body).items[0].items[0];
}
else{
object.results = error;
}
reply(object).type("application/json");
});
}
},
{
method: "GET",
path: "/api/v3/status/find/{date}",
handler: function(request, reply){
var object = {
name: "Date Look Up",
path: "/api/v3/status/find/{date}"
};
requestn({
uri: "https://api.cityofnewyork.us/311/v1/municipalservices?app_id=" + server_config.nyc311id + "&app_key=" + server_config.nyc311key + "&startDate=" + request.params.date + "&endDate=" + request.params.date,
timeout: 100000
}, function(error, response, body){
if(!error && response.statusCode == 200 && JSON.parse(body).items[0].items !== undefined){
object.results = JSON.parse(body).items[0].items[0];
}
else{
object.results = error;
}
reply(object).type("application/json");
});
}
},
{
method: "*",
path: "/{path*}",
handler:{
directory:{
path: ["./node_modules/", "./static/"],
listing: false,
redirectToSlash: true
}
}
}
];
exports.paths = paths;