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",
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) => {
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'
......
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;
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