Commit 7ac8f13d authored by wty's avatar wty

更改连接池,尝试更改路由方法

parent 60c96dd7
......@@ -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",
'connectionLimit': 1000
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
......
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) => {
const SQL = 'SELECT * FROM type'
Mysql.query(SQL, (err, result) => {
if (err) {
getMysql.then(Mysql => {
router.get('/queryType', (req, res) => {
const SQL = 'SELECT * FROM type'
Mysql.query(SQL, (err, result) => {
if (err) {
res.send({
success: false,
err
})
}
res.send({
success: false,
err
success: true,
data: result
})
}
res.send({
success: true,
data: result
})
})
});
});
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) => {
if (err) {
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) => {
if (err) {
res.send({
success: false,
err
})
}
res.send({
success: false,
err
success: true,
data: result
})
}
res.send({
success: true,
data: result
})
})
});
});
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){
SQL = `SELECT * FROM toolbox`
}
if (isFollow) {
type_id = JSON.parse(type_id)
SQL = 'SELECT * FROM toolbox WHERE toolbox_id IN (?)'
}
Mysql.query(SQL, [type_id], (err, result) => {
if (err) {
res.send({
success: false,
err
})
throw err
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){
SQL = `SELECT * FROM toolbox`
}
if (isFollow) {
type_id = JSON.parse(type_id)
SQL = 'SELECT * FROM toolbox WHERE toolbox_id IN (?)'
}
Mysql.query(SQL, [type_id], (err, result) => {
if (err) {
res.send({
success: false,
err
})
throw err
}
res.send({
success: true,
data: result
res.send({
success: true,
data: result
})
})
})
});
});
}).catch(e => console.error(e))
// router.get('/queryToolBoxSortId', (req, res) => {
// const SQL = 'SELECT sortId FROM toolbox'
......
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) {
let {uid} = req.cookies
if (!uid){
uid = req.query.uid
}
// if (!uid) {
// res.send({
// success: false,
// code: ErrorCode.USER_NOT_LOGIN,
// data: '用户尚未登录'
// })
// return
// }
const SQL = 'SELECT * FROM `user` WHERE `user`.uid = ?'
Mysql.query(SQL, [uid], (err, result) => {
if (err || !result || !result.length) {
res.send({
success: false,
err
})
return
getMysql.then(Mysql => {
/* GET users listing. */
router.get('/getUser', function (req, res, next) {
let {uid} = req.cookies
if (!uid){
uid = req.query.uid
}
console.log(result)
const _result = result.slice()
_result[0].follow = JSON.parse(_result[0].follow)
res.send({
success: true,
data: {
..._result[0],
// if (!uid) {
// res.send({
// success: false,
// code: ErrorCode.USER_NOT_LOGIN,
// data: '用户尚未登录'
// })
// return
// }
const SQL = 'SELECT * FROM `user` WHERE `user`.uid = ?'
Mysql.query(SQL, [uid], (err, result) => {
if (err || !result || !result.length) {
res.send({
success: false,
err
})
return
}
})
})
});
router.get('/login', (req, res) => {
const {uid} = req.query
const SQL = 'SELECT * FROM `user` WHERE `user`.uid = ?'
Mysql.query(SQL, [uid], (err, result) => {
if (err) {
res.send({
success: false,
err
})
throw err
}
if (!!result && result[0].uid) {
res.cookie('uid', result[0].uid)
console.log(result)
const _result = result.slice()
_result[0].follow = JSON.parse(_result[0].follow)
res.send({
success: true,
data: '登录成功!'
})
} else {
res.send({
success: false,
data: '登录失败,用户不存在'
data: {
..._result[0],
}
})
}
})
});
router.get('/login', (req, res) => {
const {uid} = req.query
const SQL = 'SELECT * FROM `user` WHERE `user`.uid = ?'
Mysql.query(SQL, [uid], (err, result) => {
if (err) {
res.send({
success: false,
err
})
throw err
}
if (!!result && result[0].uid) {
res.cookie('uid', result[0].uid)
res.send({
success: true,
data: '登录成功!'
})
} else {
res.send({
success: false,
data: '登录失败,用户不存在'
})
}
})
})
})
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) => {
if (err) {
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) => {
if (err) {
res.send({
success: false,
err
})
return
}
res.send({
success: false,
err
success: true,
})
return
}
res.send({
success: true,
})
})
}).catch(e => {
console.error(e)
})
module.exports = router;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment