app.js
1.88 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
var express = require('express');
var app = express();
var fs = require('fs');
app.use(function(req, res, next){
console.log('%s %s', req.method, req.url);
next();
});
app.use(express.static(__dirname + '/public'));
app.use(express.bodyParser());
//index
app.get('/',function(req,res)
{
var html = '<!doctype html><html><head><title>U Up Up!</title> <meta name="google-site-verification" content="cQoYR2ncKEPvT919ZOGe_-X34kitFX8ijFoJ1sdAnA0" /><link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Lemon"> <head><body style="background:#000 url(http://farm8.staticflickr.com/7292/8825786798_883bee009d_o.jpg) center 0 no-repeat;color:#fff;background-size:100%"><h1 style="font-family:Lemon;text-align:center">U Up Up!</h1></body></html>'
res.setHeader('Content-Type','text/html');
res.setHeader('Content-length',html.length);
res.end(html);
});
var FB = require('fb');
app.get('/fb',function(req,res)
{
var data = req.param('data');
data = JSON.parse(data);
var method = data.method;
var fields = {fields:data.fields};
if(data.limit)
{
fields.offset = data.offset;
fields.limit = data.limit;
}
var at = data.accessToken
FB.setAccessToken(at);
console.log(fields);
if(data.fields)
{
FB.api(method,fields,function (resp)
{
console.log(resp);
res.send(resp);
});
}
else
{
FB.api(method,function (resp)
{
console.log(resp);
res.send(resp);
});
}
});
app.post('/fb',function(req,res)
{
var data = req.body.data;
data = JSON.parse(data);
console.log(data);
var method = data.method;
var body = data.body;
var at = data.accessToken
FB.setAccessToken(at);
FB.api(method,'post',body,function (resp)
{
console.log(resp);
res.send(resp);
});
});
app.listen(80);
console.log('OK!');