-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
56 lines (52 loc) · 1.13 KB
/
Copy pathindex.js
File metadata and controls
56 lines (52 loc) · 1.13 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
const OAuth = require("oauth");
const url = require("url");
module.exports = (req, res) => {
const header = {
"Yahoo-App-Id": process.env.YAHOO_APP_ID
};
const { path } = url.parse(req.url);
const request = new OAuth.OAuth(
null,
null,
process.env.YAHOO_CONSUMER_KEY,
process.env.YAHOO_CONSUMER_SECRET,
"1.0",
null,
"HMAC-SHA1",
null,
header
);
request.get(
"https://weather-ydn-yql.media.yahoo.com" + path,
null,
null,
(err, data, result) => {
if (err) {
res.end(
JSON.stringify({
error: "Error occurred while contacting Yahoo APIs"
})
);
} else {
try {
const jsonData = JSON.stringify(data);
if (jsonData) {
res.end(jsonData);
} else {
res.end(
JSON.stringify({
error: "No response data"
})
);
}
} catch (err) {
res.end(
JSON.stringify({
error: "Error occurred while parsing json response"
})
);
}
}
}
);
};