Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
Dui123
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
王天宇
Dui123
Commits
7ac8f13d
Commit
7ac8f13d
authored
Oct 21, 2021
by
wty
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更改连接池,尝试更改路由方法
parent
60c96dd7
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
145 additions
and
147 deletions
+145
-147
SQLPool.js
server/SQLPool.js
+23
-30
query.js
server/routes/query.js
+52
-49
users.js
server/routes/users.js
+70
-68
No files found.
server/SQLPool.js
View file @
7ac8f13d
...
...
@@ -3,37 +3,30 @@ const MYSQL = require('mysql')
const
config
=
require
(
'../config/dev.json'
)
const
request
=
require
(
'request'
)
// request(config['remote_config_url'],{},(error, request, body)=>{
// const data = JSON.parse(body)
// const source = data['propertySources'][0]['source']
// const username = source['apollo.mysql.duiba_web_tool.username']
// const password = source['apollo.mysql.duiba_web_tool.password']
// const database = source['apollo.mysql.duiba_web_tool.database']
// const host = source['apollo.mysql.duiba_web_tool.url'].split(':')[0]
// const port = source['apollo.mysql.duiba_web_tool.url'].split(':')[1]
// const Mysql = MYSQL.createPool({
// 'host': host,
// 'port': port,
// 'user': username,
// 'password': password,
// 'database': database,
// 'connectionLimit': 1000
// })
// console.info('MysqlConfig:',Mysql.config)
// console.info('OBJMysql',Mysql)
// module.exports = Mysql
// })
const
Mysql
=
MYSQL
.
createPool
({
'host'
:
'rm-bp1jglyqbhi8qwf0a.mysql.rds.aliyuncs.com'
,
'port'
:
3306
,
'user'
:
"duiba_dev"
,
'password'
:
"dbseccode3qTecHjXZCTSNmptANeMVnAURVVzgSoj"
,
'database'
:
"duiba_web_tool"
,
const
getMysql
=
new
Promise
((
resolve
)
=>
{
request
(
config
[
'remote_config_url'
],{},(
error
,
request
,
body
)
=>
{
const
data
=
JSON
.
parse
(
body
)
const
source
=
data
[
'propertySources'
][
0
][
'source'
]
const
username
=
source
[
'apollo.mysql.duiba_web_tool.username'
]
const
password
=
source
[
'apollo.mysql.duiba_web_tool.password'
]
const
database
=
source
[
'apollo.mysql.duiba_web_tool.database'
]
const
host
=
source
[
'apollo.mysql.duiba_web_tool.url'
].
split
(
':'
)[
0
]
const
port
=
source
[
'apollo.mysql.duiba_web_tool.url'
].
split
(
':'
)[
1
]
const
Mysql
=
MYSQL
.
createPool
({
'host'
:
host
,
'port'
:
port
,
'user'
:
username
,
'password'
:
password
,
'database'
:
database
,
'connectionLimit'
:
1000
})
console
.
info
(
'MysqlConfig:'
,
Mysql
.
config
)
console
.
info
(
'OBJMysql'
,
Mysql
)
resolve
(
Mysql
)
})
})
console
.
info
(
'MysqlConfig:'
,
Mysql
.
config
)
console
.
info
(
'OBJMysql'
,
Mysql
)
module
.
exports
=
Mysql
module
.
exports
=
getMysql
...
...
server/routes/query.js
View file @
7ac8f13d
const
express
=
require
(
'express'
)
const
request
=
require
(
"request"
);
const
Mysql
=
require
(
'../SQLPool'
)
// const Mysql = require('../SQLPool')
const
getMysql
=
require
(
'../SQLPool'
)
const
router
=
express
.
Router
()
router
.
get
(
'/queryType'
,
(
req
,
res
)
=>
{
getMysql
.
then
(
Mysql
=>
{
router
.
get
(
'/queryType'
,
(
req
,
res
)
=>
{
const
SQL
=
'SELECT * FROM type'
Mysql
.
query
(
SQL
,
(
err
,
result
)
=>
{
if
(
err
)
{
...
...
@@ -17,9 +18,9 @@ router.get('/queryType', (req, res) => {
data
:
result
})
})
});
});
router
.
get
(
'/queryChildType'
,
(
req
,
res
)
=>
{
router
.
get
(
'/queryChildType'
,
(
req
,
res
)
=>
{
const
{
type_id
}
=
req
.
query
const
SQL
=
'SELECT child_type.child_type_id, child_type.child_type_name, child_type.type_id FROM child_type INNER JOIN type ON child_type.type_id = type.type_id WHERE type.type_id = ?'
Mysql
.
query
(
SQL
,[
type_id
],
(
err
,
result
)
=>
{
...
...
@@ -34,10 +35,10 @@ router.get('/queryChildType', (req, res) => {
data
:
result
})
})
});
});
router
.
get
(
'/queryToolBox'
,
(
req
,
res
)
=>
{
router
.
get
(
'/queryToolBox'
,
(
req
,
res
)
=>
{
let
{
isFollow
,
type_id
}
=
req
.
query
let
SQL
=
`SELECT toolbox.*, type_childtype_toolbox.child_type_id FROM type_childtype_toolbox INNER JOIN toolbox ON type_childtype_toolbox.toolbox_id = toolbox.toolbox_id WHERE type_childtype_toolbox.type_id = ?`
if
(
!
isFollow
&&
!
type_id
){
...
...
@@ -61,7 +62,9 @@ router.get('/queryToolBox', (req, res) => {
data
:
result
})
})
});
});
}).
catch
(
e
=>
console
.
error
(
e
))
// router.get('/queryToolBoxSortId', (req, res) => {
// const SQL = 'SELECT sortId FROM toolbox'
...
...
server/routes/users.js
View file @
7ac8f13d
const
express
=
require
(
'express'
);
const
Mysql
=
require
(
'../SQLPool'
)
const
router
=
express
.
Router
();
const
getMysql
=
require
(
'../SQLPool'
)
const
ErrorCode
=
{
USER_NOT_LOGIN
:
70001
}
/* GET users listing. */
router
.
get
(
'/getUser'
,
function
(
req
,
res
,
next
)
{
getMysql
.
then
(
Mysql
=>
{
/* GET users listing. */
router
.
get
(
'/getUser'
,
function
(
req
,
res
,
next
)
{
let
{
uid
}
=
req
.
cookies
if
(
!
uid
){
uid
=
req
.
query
.
uid
...
...
@@ -40,9 +40,9 @@ router.get('/getUser', function (req, res, next) {
}
})
})
});
});
router
.
get
(
'/login'
,
(
req
,
res
)
=>
{
router
.
get
(
'/login'
,
(
req
,
res
)
=>
{
const
{
uid
}
=
req
.
query
const
SQL
=
'SELECT * FROM `user` WHERE `user`.uid = ?'
Mysql
.
query
(
SQL
,
[
uid
],
(
err
,
result
)
=>
{
...
...
@@ -66,9 +66,9 @@ router.get('/login', (req, res) => {
})
}
})
})
})
router
.
get
(
'/follow'
,
(
req
,
res
)
=>
{
router
.
get
(
'/follow'
,
(
req
,
res
)
=>
{
const
{
follow
,
uid
}
=
req
.
query
const
SQL
=
'UPDATE user SET follow = ? WHERE uid = ?'
Mysql
.
query
(
SQL
,
[
follow
,
uid
],
(
err
,
result
)
=>
{
...
...
@@ -83,6 +83,8 @@ router.get('/follow', (req, res) => {
success
:
true
,
})
})
})
}).
catch
(
e
=>
{
console
.
error
(
e
)
})
module
.
exports
=
router
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment