-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapi.js
58 lines (50 loc) · 1.45 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
57
58
feedsapi = require("../api/feeds.js");
url = require('url')
querystring = require('querystring')
firebase = require('firebase')
exports.feedOfNote = function(req, res) {
/*/feeds/note request
*/
var note, params, urlData, validParams;
console.log("feeds/note api");
urlData = url.parse(req.url);
params = querystring.parse(urlData.query);
validParams = feedsapi.validateNoteParam(params);
/*param validation
*/
if (validParams) {
note = new firebase("https://wiredancer.firebaseio.com/note");
return note.once("value", function(snapshot) {
var result;
result = feedsapi.query(snapshot.val(), 'note', validParams);
res.write(result);
return res.end();
});
} else {
res.write("Could not understand your request");
return res.end();
}
}
exports.feedOfUser = function(req, res) {
/*/feeds/user request
*/
var note, params, urlData, validParams;
console.log("feeds/user api");
urlData = url.parse(req.url);
params = querystring.parse(urlData.query);
validParams = feedsapi.validateUserParam(params);
/*param validation
*/
if (validParams) {
note = new firebase("https://wiredancer.firebaseio.com/user");
return note.once("value", function(snapshot) {
var result;
result = feedsapi.query(snapshot.val(), 'user', validParams);
res.write(result);
return res.end();
});
} else {
res.write("Could not understand your request");
return res.end();
}
}