Skip to content

Commit 525c16f

Browse files
committed
测试bigpipe
1 parent 02962ba commit 525c16f

File tree

10 files changed

+1411
-54
lines changed

10 files changed

+1411
-54
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,6 @@ http://hi.baidu.com/tang_guangyao/item/302a9d1a9976c06ae65e0643
3636

3737
使用外网免费数据库https://app.mongohq.com
3838

39-
测试部署分支
39+
测试部署分支
40+
41+
尝试bigpige

app.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ app.use(express.bodyParser({uploadDir:'./uploads'}));
2424
//app.use(express.bodyParser());
2525
app.use(express.methodOverride());
2626
app.use(express.cookieParser());
27-
// app.use(express.session({
28-
// secret: settings.cookieSecret,
29-
// key: settings.db,
30-
// cookie: {maxAge: 1000 * 60 * 60 * 24 * 30},//30 days
31-
// store: new MongoStore({
32-
// db: settings.db
33-
// })
34-
// }));
3527
app.use(express.session({
3628
secret: settings.cookieSecret,
29+
key: settings.db,
3730
cookie: {maxAge: 1000 * 60 * 60 * 24 * 30},//30 days
38-
url: settings.url
31+
store: new MongoStore({
32+
db: settings.db
33+
})
3934
}));
35+
// app.use(express.session({
36+
// secret: settings.cookieSecret,
37+
// cookie: {maxAge: 1000 * 60 * 60 * 24 * 30},//30 days
38+
// url: settings.url
39+
// }));
4040
//声明静态引用在前,路由规则在后
4141
app.use(express.static(path.join(__dirname, 'public')));
4242
app.use(app.router);

models/connect.js

+4-13
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,8 @@
22
保持数据库一直连接,保存一个全局变量
33
*/
44

5-
var mongodb = require('mongodb').Db;
6-
var settings = require('../settings');
5+
var mongodb = require('./db');
76

8-
// var mongodb = require('./db'),
9-
// settings = require('../settings');
10-
11-
// mongodb.open(settings.url,function(err,db){
12-
// global.db=db;
13-
// });
14-
15-
16-
mongodb.connect(settings.url, function (err, db) {
17-
global.db=db;
18-
});
7+
mongodb.open(function(err,db){
8+
global.db=db;
9+
});

models/db.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// var settings = require('../settings'),
2-
// Db = require('mongodb').Db,
3-
// Connection = require('mongodb').Connection,
4-
// Server = require('mongodb').Server;
1+
var settings = require('../settings'),
2+
Db = require('mongodb').Db,
3+
Connection = require('mongodb').Connection,
4+
Server = require('mongodb').Server;
55

6-
// module.exports = new Db(settings.db, new Server(settings.host, Connection.DEFAULT_PORT, {}), {safe: true});
6+
module.exports = new Db(settings.db, new Server(settings.host, Connection.DEFAULT_PORT, {}), {safe: true});
77

88

public/js/bigpipe.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var Bigpipe=function(){
2+
this.callbacks={};
3+
}
4+
5+
Bigpipe.prototype.ready=function(key,callback){
6+
if(!this.callbacks[key]){
7+
this.callbacks[key]=[];
8+
}
9+
this.callbacks[key].push(callback);
10+
}
11+
12+
Bigpipe.prototype.set=function(key,data){
13+
var callbacks=this.callbacks[key]||[];
14+
for(var i=0;i<callbacks.length;i++){
15+
callbacks[i].call(this,data);
16+
}
17+
}

public/js/tgy/index.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function IndexCtrl($scope, $http, $templateCache) {
3737
//如果没有信息,就不请求
3838
return;
3939
}
40-
$scope.url = 'http://xueqiu.com/stock/quote.json?code='+stockCode+'&key=47bce5c74f&access_token=qPVhzoKJWIL1o3UCSgUfRK&_=1389259380479&callback=JSON_CALLBACK';
40+
$scope.url = 'http://xueqiu.com/stock/quote.json?code='+stockCode+'&key=47bce5c74f&access_token=qPVhzoKJWIL1o3UCSgUfRK&_=1389603586048&callback=JSON_CALLBACK';
4141
$scope.code = null;
4242
$scope.response = null;
4343
$http({method: $scope.method, url: $scope.url, cache: $templateCache}).
@@ -95,6 +95,11 @@ function IndexCtrl($scope, $http, $templateCache) {
9595
$scope.topList=topList=data.list;
9696
}
9797
});
98+
//bigpipe请求热门股
99+
var bigpipe=new Bigpipe();
100+
bigpipe.ready('hotStock',function(data){
101+
var l;
102+
})
98103

99104
//请求热门用户
100105
//由于后端同时请求了热门股票,会导致mongodb同时开启导致bug,暂时注释
@@ -214,7 +219,7 @@ function IndexCtrl($scope, $http, $templateCache) {
214219
$scope.topList=newTopList;
215220
//刷新我的收藏
216221
$scope.addMethod = 'JSONP';
217-
$scope.addUrl = 'http://xueqiu.com/stock/quote.json?code='+topStockUid+'&key=47bce5c74f&access_token=gbQtYjUWioQ9DQWGpDIREK&_=1386664870607&callback=JSON_CALLBACK';
222+
$scope.addUrl = 'http://xueqiu.com/stock/quote.json?code='+topStockUid+'&key=47bce5c74f&access_token=qPVhzoKJWIL1o3UCSgUfRK&_=1389603586048&callback=JSON_CALLBACK';
218223
$http({method: $scope.addMethod, url: $scope.addUrl, cache: $templateCache}).
219224
success(function(data, status) {
220225
//请求关注的数据

0 commit comments

Comments
 (0)