Dotos 8 лет назад
Родитель
Сommit
df08e876ad
8 измененных файлов с 144 добавлено и 93 удалено
  1. 1 0
      .avoscloud/apps.json
  2. 1 1
      .gitignore
  3. 26 9
      app.js
  4. 50 46
      package.json
  5. 1 1
      routes/ip.js
  6. 2 1
      routes/welcome.js
  7. 62 35
      static/css/style.css
  8. 1 0
      views/welcome.pug

+ 1 - 0
.avoscloud/apps.json

@@ -0,0 +1 @@
+{"origin":"z3bnu4iiAfsfAAUxAKaIjNO2-gzGzoHsz"}

+ 1 - 1
.gitignore

@@ -2,4 +2,4 @@
 .DS_Store
 node_modules/
 npm-debug.log
-config/
+config/.avoscloud/

+ 26 - 9
app.js

@@ -5,7 +5,7 @@ var favicon = require('serve-favicon');
 var logger = require('morgan');
 var cookieParser = require('cookie-parser');
 var bodyParser = require('body-parser');
-var sass = require('node-sass-middleware');
+//var sass = require('node-sass-middleware');
 var moment = require('moment');
 //设置时区
 var timezone = require('moment-timezone');
@@ -31,6 +31,14 @@ var weather = require('./routes/weather');
 var test = require('./routes/test');
 
 var app = express();
+//引入LeanCloud
+//var AV = require('leanengine');
+// AV.init({
+//     appId: process.env.LEANCLOUD_APP_ID,
+//     appKey: process.env.LEANCLOUD_APP_KEY,
+//     masterKey: process.env.LEANCLOUD_APP_MASTER_KEY
+// });
+//app.use(AV.express());
 app.set('views', path.join(__dirname, 'views'));
 // view engine setup
 app.set('view engine', 'pug');
@@ -42,19 +50,27 @@ app.use(bodyParser.json());
 app.use(bodyParser.urlencoded({ extended: false }));
 app.use(cookieParser());
 //配置 sass
-app.use(sass({
-    src: __dirname + '/static/sass',
-    dest: __dirname + '/static/css',
-    indentedSyntax: true,
-    sourceMap: true
-}));
+// app.use(sass({
+//     src: __dirname + '/static/sass',
+//     dest: __dirname + '/static/css',
+//     indentedSyntax: true,
+//     sourceMap: true
+// }));
 //静态文件访问路径
 app.use('/static/', express.static(path.join(__dirname, 'static')));
+var i = 0;
+//每隔3分钟自动请求一次
+setInterval(function() {
+    request('https://bird.ioliu.cn/joke?_detect=' + i++, function(err, response, body) {
+
+    });
+}, 3 * 60 * 1000);
 
 /***
  * 全局过滤:统计和日志
  */
-app.all('*', function(req, res, next) {
+app.use(function(req, res, next) {
+
     res.header("Access-Control-Allow-Origin", "*");
     res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept,Access-Control-Allow-Origin");
     res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
@@ -62,7 +78,7 @@ app.all('*', function(req, res, next) {
     res.header("Vary", "Origin");
     var protocol = req.protocol;
     var host = req.hostname;
-    var ip = req.ip.replace(/::ffff:/, '');
+    var ip = req.headers['x-real-ip'] ? req.headers['x-real-ip'] : req.ip.replace(/::ffff:/, '');
     var ref = req.headers.referer;
     var originalUrl = req.originalUrl;
     var logs = {
@@ -116,6 +132,7 @@ app.use('/weather', weather);
 app.use(function(req, res, next) {
     var err = new Error('Not Found');
     err.status = 404;
+
     next(err);
 });
 

+ 50 - 46
package.json

@@ -1,47 +1,51 @@
 {
-  "name": "JsonBird",
-  "version": "1.4.0",
-  "description": "A Remote Json Agent Service",
-  "author": {
-    "name": "xCss",
-    "mail": "yy.liu@foxmail.com"
-  },
-  "license": "MIT",
-  "private": true,
-  "scripts": {
-    "start": "node ./bin/www"
-  },
-  "repository": {
-    "type": "git",
-    "url": "git+https://github.com/xCss/JsonBird.git"
-  },
-  "keywords": [
-    "JsonBird",
-    "JsonProxy"
-  ],
-  "bugs": {
-    "url": "https://github.com/xCss/JsonBird/issues"
-  },
-  "readme": "./readme.md",
-  "homepage": "https://github.com/xCss/JsonBird#readme",
-  "dependencies": {
-    "bcryptjs": "^2.3.0",
-    "body-parser": "~1.15.1",
-    "cluster": "^0.7.7",
-    "cookie-parser": "~1.4.3",
-    "debug": "~2.2.0",
-    "express": "~4.13.4",
-    "express-generator": "^4.13.4",
-    "moment": "^2.15.0",
-    "moment-timezone": "^0.5.5",
-    "morgan": "~1.7.0",
-    "mysql": "^2.11.1",
-    "node-sass": "^3.10.0",
-    "node-sass-middleware": "^0.9.8",
-    "os": "^0.1.1",
-    "pug": "^2.0.0-beta6",
-    "querystring": "^0.2.0",
-    "request": "^2.74.0",
-    "serve-favicon": "~2.3.0"
-  }
-}
+    "name": "JsonBird",
+    "version": "1.4.0",
+    "description": "A Remote Json Agent Service",
+    "author": {
+        "name": "xCss",
+        "mail": "yy.liu@foxmail.com"
+    },
+    "license": "MIT",
+    "private": true,
+    "scripts": {
+        "start": "node ./bin/www"
+    },
+    "repository": {
+        "type": "git",
+        "url": "git+https://github.com/xCss/JsonBird.git"
+    },
+    "keywords": [
+        "JsonBird",
+        "JsonProxy"
+    ],
+    "bugs": {
+        "url": "https://github.com/xCss/JsonBird/issues"
+    },
+    "readme": "./readme.md",
+    "homepage": "https://github.com/xCss/JsonBird#readme",
+    "dependencies": {
+        "bcryptjs": "^2.3.0",
+        "body-parser": "~1.15.1",
+        "cluster": "^0.7.7",
+        "cookie-parser": "~1.4.3",
+        "debug": "~2.2.0",
+        "express": "~4.13.4",
+        "express-generator": "^4.13.4",
+        "leanengine": "^1.2.2",
+        "moment": "^2.15.0",
+        "moment-timezone": "^0.5.5",
+        "morgan": "~1.7.0",
+        "mysql": "^2.11.1",
+        "node-sass": "^3.10.0",
+        "node-sass-middleware": "^0.9.8",
+        "os": "^0.1.1",
+        "pug": "^2.0.0-beta6",
+        "querystring": "^0.2.0",
+        "request": "^2.74.0",
+        "serve-favicon": "~2.3.0"
+    },
+    "engines": {
+        "node": "6.x"
+    }
+}

+ 1 - 1
routes/ip.js

@@ -12,7 +12,7 @@ router.post('/*', function(req, res, next) {
  * 获取IP地址所对应的地区
  */
 function ip2address(req, res, next) {
-    let ip = req.query.ip || req.body.ip || req.ip.replace(/\:\:1/, '127.0.0.1');
+    let ip = req.query.ip || req.body.ip || req.headers['x-real-ip'] || req.ip.replace(/\:\:1/, '127.0.0.1');
     let callback = req.query.callback || req.body.callback;
     let type = req.query.type || req.body.type;
     let url = base + '&ip=' + ip + '&dtype=' + type;

+ 2 - 1
routes/welcome.js

@@ -5,7 +5,8 @@ let router = express.Router();
 
 /* GET home page. */
 router.get('/', function(req, res, next) {
-    let ip = req.ip;
+    //let ip = req.ip;
+    let ip = req.headers['x-real-ip'];
     ip2addr(ip, function(data) {
         let params = {
             head: config.title,

+ 62 - 35
static/css/style.css

@@ -1,45 +1,61 @@
 @import 'reset.css';
-html,body{height:100%;overflow: hidden;background: -webkit-linear-gradient(300deg,#23213d,#2e383f);
-    background: linear-gradient(150deg,#23213d,#2e383f);}
-.section-center{
-   display: -webkit-box;   /* OLD: Safari,  iOS, Android browser, older WebKit browsers.  */
-   display: -moz-box;      /* OLD: Firefox (buggy) */
-   display: -ms-flexbox;   /* MID: IE 10 */
-   display: -webkit-flex;  /* NEW, Chrome 21–28, Safari 6.1+ */
-   display: flex;          /* NEW: IE11, Chrome 29+, Opera 12.1+, Firefox 22+ */
-
-   -webkit-box-align: center; -moz-box-align: center; /* OLD… */
-   -ms-flex-align: center; /* You know the drill now… */
-   -webkit-align-items: center;
-   align-items: center;
-
-   -webkit-box-pack: center; -moz-box-pack: center;
-   -ms-flex-pack: center;
-   -webkit-justify-content: center;
-   justify-content: center;
+html,
+body {
+    height: 100%;
+    overflow: hidden;
+    background: -webkit-linear-gradient(300deg, #23213d, #2e383f);
+    background: linear-gradient(150deg, #23213d, #2e383f);
+}
 
-   margin: 0;
-   height: 100%;
-   width: 100%; /* needed for Firefox */
-   position:absolute;
-   text-align: center;
+.section-center {
+    display: -webkit-box;
+    /* OLD: Safari,  iOS, Android browser, older WebKit browsers.  */
+    display: -moz-box;
+    /* OLD: Firefox (buggy) */
+    display: -ms-flexbox;
+    /* MID: IE 10 */
+    display: -webkit-flex;
+    /* NEW, Chrome 21–28, Safari 6.1+ */
+    display: flex;
+    /* NEW: IE11, Chrome 29+, Opera 12.1+, Firefox 22+ */
+    -webkit-box-align: center;
+    -moz-box-align: center;
+    /* OLD… */
+    -ms-flex-align: center;
+    /* You know the drill now… */
+    -webkit-align-items: center;
+    align-items: center;
+    -webkit-box-pack: center;
+    -moz-box-pack: center;
+    -ms-flex-pack: center;
+    -webkit-justify-content: center;
+    justify-content: center;
+    margin: 0;
+    height: 100%;
+    width: 100%;
+    /* needed for Firefox */
+    position: absolute;
+    text-align: center;
 }
 
-.section-center .container{
-  width:100%;
-  color:#fff;
+.section-center .container {
+    width: 100%;
+    color: #fff;
 }
-.section-center .container .cover{
-    font-size:18px;  
+
+.section-center .container .cover {
+    font-size: 18px;
     margin-bottom: 30px;
     font-weight: 400;
 }
-.section-center .container .heading{
-    margin-bottom:10px;
-    text-shadow: 1px 1px 1px rgba(0,0,0,.3);
+
+.section-center .container .heading {
+    margin-bottom: 10px;
+    text-shadow: 1px 1px 1px rgba(0, 0, 0, .3);
     font-weight: 100;
     font-size: 4.5rem;
 }
+
 .btn {
     display: inline-block;
     margin-bottom: 0;
@@ -61,19 +77,30 @@ html,body{height:100%;overflow: hidden;background: -webkit-linear-gradient(300de
     -ms-user-select: none;
     user-select: none;
 }
-.btn.focus, .btn:focus, .btn:hover {
+
+.btn+.btn {
+    margin-left: 15px;
+}
+
+.btn.focus,
+.btn:focus,
+.btn:hover {
     color: #333;
     text-decoration: none;
 }
+
 .btn-ghost-light {
     padding: 8px 32px;
 }
-.btn-ghost-light, .btn-ghost-light:focus{
+
+.btn-ghost-light,
+.btn-ghost-light:focus {
     border: 1px solid #fff;
-    background-color: rgba(155,163,175,0);
+    background-color: rgba(155, 163, 175, 0);
     color: #fff;
 }
+
 .btn-ghost-light:hover {
-    background-color: rgba(155,163,175,.1);
+    background-color: rgba(155, 163, 175, .1);
     color: #fff;
 }

+ 1 - 0
views/welcome.pug

@@ -6,6 +6,7 @@ block content
             div.cover.heading #{head}
             div.cover.description #{description}<br>#{address}
             div.cover.action
+                a.btn.btn-ghost-light(href="https://github.com/xCss/JsonBird/wiki/All-APIs",target="_blank") Wiki
                 a.btn.btn-ghost-light(href="/v1/?url=http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1") Quick Start
 
     script(src="/static/libs/three/three.min.js")