Skip to content

Commit 4a497ec

Browse files
committed
解决前端跨域请求雪球网url参数变换的问题
1 parent 214b4ef commit 4a497ec

File tree

7 files changed

+28
-22
lines changed

7 files changed

+28
-22
lines changed

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,10 @@ b. 聊天记录可以设置缓存数量,默认为20条,如果超过20条会
2727

2828
9. 尝试bigpige,首页利用bigpipe,加载热门股票和热门用户,并且和angular结合使用
2929

30-
10. 使用外网免费数据库https://app.mongohq.com
30+
10. 使用外网免费数据库https://app.mongohq.com
31+
32+
11. 跨域请求的雪球网具体股票数据
33+
34+
35+
36+
更新说明:因为股票具体数据是跨域请求的雪球网接口,雪球接口的参数会定时改变,所以对接口参数处理了一下,放入views的top.ejs文件中。

config.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
*/
44
exports.config = {
55
talkHistoryCache: 20 // 聊天记录缓存数量
6+
67
};

public/js/tgy/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function IndexCtrl($scope, $http, $templateCache) {
3838
//如果没有信息,就不请求
3939
return;
4040
}
41-
$scope.url = 'http://xueqiu.com/stock/quote.json?code='+stockCode+'&key=47bce5c74f&access_token=qPVhzoKJWIL1o3UCSgUfRK&_=1389603586048&callback=JSON_CALLBACK';
41+
$scope.url = 'http://xueqiu.com/stock/quote.json?code='+stockCode+'&'+xueqiuUrl+'&callback=JSON_CALLBACK';
4242
$scope.code = null;
4343
$scope.response = null;
4444
$http({method: $scope.method, url: $scope.url, cache: $templateCache}).
@@ -256,7 +256,7 @@ function IndexCtrl($scope, $http, $templateCache) {
256256
$scope.topList=newTopList;
257257
//刷新我的收藏
258258
$scope.addMethod = 'JSONP';
259-
$scope.addUrl = 'http://xueqiu.com/stock/quote.json?code='+topStockUid+'&key=47bce5c74f&access_token=qPVhzoKJWIL1o3UCSgUfRK&_=1389603586048&callback=JSON_CALLBACK';
259+
$scope.addUrl = 'http://xueqiu.com/stock/quote.json?code='+topStockUid+'&'+xueqiuUrl+'&callback=JSON_CALLBACK';
260260
$http({method: $scope.addMethod, url: $scope.addUrl, cache: $templateCache}).
261261
success(function(data, status) {
262262
//请求关注的数据

public/js/tgy/peo.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
angular.module('App', []);
1+
//angular.module('App', []);
22

33
function peopleCtrl($scope, $http, $templateCache){
44
var selfName=$("#headShowName").text();
@@ -50,7 +50,7 @@ function peopleCtrl($scope, $http, $templateCache){
5050
//如果没有信息,就不请求
5151
return;
5252
}
53-
$scope.url = 'http://xueqiu.com/stock/quote.json?code='+stockCode+'&key=47bce5c74f&access_token=gbQtYjUWioQ9DQWGpDIREK&_=1386664870607&callback=JSON_CALLBACK';
53+
$scope.url = 'http://xueqiu.com/stock/quote.json?code='+stockCode+'&'+xueqiuUrl+'&callback=JSON_CALLBACK';
5454
$scope.code = null;
5555
$scope.response = null;
5656
$http({method: $scope.method, url: $scope.url, cache: $templateCache}).
@@ -209,4 +209,7 @@ function peopleCtrl($scope, $http, $templateCache){
209209
};
210210
//初始化我的话题
211211
angular.init();
212-
}
212+
}
213+
214+
215+
angular.bootstrap(document.documentElement);

public/js/tgy/sto.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
angular.module('App', []);
1+
//angular.module('App', []);
22

33
function FetchCtrl($scope, $http, $templateCache) {
44
//用户名
@@ -126,7 +126,7 @@ function FetchCtrl($scope, $http, $templateCache) {
126126

127127
//定时获取实时数据
128128
$scope.method = 'JSONP';
129-
$scope.url = 'http://xueqiu.com/stock/quote.json?code='+pathUrl+'&access_token=qPVhzoKJWIL1o3UCSgUfRK&_=1389259380479&callback=JSON_CALLBACK';
129+
$scope.url = 'http://xueqiu.com/stock/quote.json?code='+pathUrl+'&'+xueqiuUrl+'&callback=JSON_CALLBACK';
130130
$scope.code = null;
131131
$scope.response = null;
132132

@@ -347,4 +347,6 @@ function FetchCtrl($scope, $http, $templateCache) {
347347
//初始化
348348
stockTopic.init();
349349
};
350-
}
350+
}
351+
352+
angular.bootstrap(document.documentElement);

routes/index.js

+3-13
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ module.exports = function(app){
2323

2424
//pipe替换
2525
res.render('index', {
26-
user:req.session.user,
27-
isStock:true
28-
},function (err, str) {
26+
user:req.session.user,
27+
isStock:true
28+
},function (err, str) {
2929
//res.setHeader('content-type', 'text/html; charset=utf-8')
3030
res.write(str);
3131
})
@@ -46,16 +46,6 @@ module.exports = function(app){
4646
], function (err, results) {
4747
res.end();
4848
});
49-
// stock.bigpipeHotStock(function(data){
50-
// res.write('<script>bigpipe.set("hotStock",'+JSON.stringify(data)+');</script>');
51-
// res.end();
52-
// });
53-
// stock.bigpipeTalkHistory(req,res,function(data){
54-
// res.write('<script>bigpipe.set("hotStock",'+JSON.stringify(data)+');</script>');
55-
// });
56-
57-
58-
5949
}else{
6050
res.redirect('/login');
6151
}

views/top.ejs

+4
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,9 @@
1313
<script src="js/angular.min.js"></script>
1414

1515
<script src="/socket.io/socket.io.js"></script>
16+
<script>
17+
var xueqiuUrl="key=47bce5c74f&access_token=S8nfhytJNtRNHoV9ntmtHY&_=1392196535991";
18+
//雪球接口长变化的参数
19+
</script>
1620
</head>
1721
<body >

0 commit comments

Comments
 (0)