app.js 2.79 KB
/**
 * 翻墙代理服务
 */
var express = require('express');
var request = require('request');
var fs = require('fs');

var app = express();

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);
});

/**
 * facebook代理服务
 * 获取信息
 */
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);
	  });
	}
});

/**
 * facebook代理服务
 * 发送信息
 */
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);
    });
});

/**
 * facebook代理服务
 * 获取认证信息
 */
app.get('/fb/auth',function(req,res)
{
    FB.api(req.param("method"), 
    req.params, function (resp) 
    {
      console.log(resp);
      res.send(resp);
    });
});

/**
 * facebook代理服务
 * 发送认证信息
 */
app.post('/fb/auth',function(req,res)
{
    FB.api(req.body.method, 
    req.body, function (resp) 
    {
      console.log(resp);
      res.send(resp);
    });
});


app.listen(80);
/**
 * google代理服务
 * 根据坐标获取地理信息
 */
app.get('/google',function(req,res)
{
   request('http://maps.google.cn/maps/api/geocode/json'+req._parsedUrl.search, function (error, response, body) 
   {
    if (error && response.statusCode != 200) 
    {
       console.log(error);
    }
    res.send(body);
   });
})


console.log('OK!');