-
Notifications
You must be signed in to change notification settings - Fork 0
/
http.js
111 lines (99 loc) · 3.44 KB
/
http.js
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
var redis = require("redis");
var client = redis.createClient({auth_pass:'here_dev'});
var client0 = redis.createClient({auth_pass:'here_dev'});
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var async = require('async');
app.use(bodyParser.json()); // parse application/json
app.use(bodyParser.urlencoded({
extended: false // parse application/x-www-form-urlencoded
}));
var server = app.listen(8080, function(){
var host = server.address().address;
var port = server.address().port;
console.log('app listening at '+host+':'+port);
});
client.select(1, function(err){
if(err){
console.log(err);
}
});
app.use(express.static('./'));
app.use(express.static('css'));
app.use(express.static('js'));
app.use(express.static('fonts'));
var mysql = require('mysql');
var pool = mysql.createPool({
connectionLimit : 30,
host : 'rdsruiaj3v2uaiv.mysql.rds.aliyuncs.com',
user : 'wanghan',
password : 'wanghan',
database : 'cfets_test'
});
app.get('/entyUser', function(req, res){
if(req.query.entySrno !== undefined){
client.lrange(req.query.entySrno+'.entyUserlist', 0, -1, function(err, reply){
if(err){
console.log(err);
res.send(err);
}else{
var userArray = [];
async.each(reply, function(userSrno, callback){
client0.hget('userDtlsHash', userSrno, function(err, userReply){
if(err){
callback(err);
}else{
userReply = JSON.parse(userReply);
userArray.push({
userSrno: userReply.UDT_USER_SRNO,
userDesc: userReply.UDT_USER_DESC
});
callback();
}
});
}, function(err){
if(err){
res.send(err);
}else{
res.send(userArray);
}
});
}
});
}
});
var entyDesc = ['中', '工', '农', '电', '建', '融', '信', '金', '银', '交', '基'];
app.get('/searchDatabase', function(req, res){
pool.getConnection(function(err, connection) {
// Use the connection
var desc = entyDesc[parseInt(Math.random()*entyDesc.length)];
console.log('search '+desc);
if(err){
console.log(err);
}else{
connection.query( 'SELECT EMA_ENTY_SHRT_DESC, EMA_ENTY_SRNO FROM trdx_entity_master where EMA_ENTY_SHRT_DESC like \'%'+desc+'%\' limit 50', function(err, rows) {
if(err){
console.log(err);
}else{
res.send(rows);
}
connection.release();
});
}
// Don't use the connection here, it has been returned to the pool.
});
});
app.get('/search', function(req, res) {
console.log(req.query);
if(req.query.entyDesc !== undefined){
client.lrange('enty.'+req.query.entyDesc, 0, 50, function(err, reply){
res.send(reply);
});
}
if(req.query.assetDesc !== undefined){
client.lrange('asset.'+req.query.assetDesc, 0, 50, function(err, reply){
res.send(reply);
});
}
});