-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathapp.js
45 lines (32 loc) · 932 Bytes
/
app.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
/**
* @overview
*
* @author
* @version 2014/04/26
*/
var http = require("http");
var port = Number(process.env.PORT || 3000);
var request = require("request");
var fs = require("fs");
var url = "http://graph.facebook.com/Boo/photos?type=uploaded";
var template = "";
fs.readFile("./index.html", "utf8", function (err, result) {
template = result;
});
// also equal
// template = fs.readFileSync("./index.html", "utf8");
http.createServer(function (req, res) {
res.writeHeader(200, {"Content-Type": "text/html"});
request.get(url, function (err, body, response) {
// init data
var data = "";
response = JSON.parse(response);
response.data.forEach(function (val, idx) {
data += "<img src='" + val.images[2].source + "'>";
});
// replace data
data = template.replace("{{content}}", data);
res.end(data);
});
}).listen(port);
console.log("start server port: " + port);