Commit 7ac8f13d authored by wty's avatar wty

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

parent 60c96dd7
...@@ -3,37 +3,30 @@ const MYSQL = require('mysql') ...@@ -3,37 +3,30 @@ const MYSQL = require('mysql')
const config = require('../config/dev.json') const config = require('../config/dev.json')
const request = require('request') const request = require('request')
// request(config['remote_config_url'],{},(error, request, body)=>{ const getMysql = new Promise((resolve)=>{
// const data = JSON.parse(body) request(config['remote_config_url'],{},(error, request, body)=>{
// const source = data['propertySources'][0]['source'] const data = JSON.parse(body)
// const username = source['apollo.mysql.duiba_web_tool.username'] const source = data['propertySources'][0]['source']
// const password = source['apollo.mysql.duiba_web_tool.password'] const username = source['apollo.mysql.duiba_web_tool.username']
// const database = source['apollo.mysql.duiba_web_tool.database'] const password = source['apollo.mysql.duiba_web_tool.password']
// const host = source['apollo.mysql.duiba_web_tool.url'].split(':')[0] const database = source['apollo.mysql.duiba_web_tool.database']
// const port = source['apollo.mysql.duiba_web_tool.url'].split(':')[1] const host = source['apollo.mysql.duiba_web_tool.url'].split(':')[0]
// const Mysql = MYSQL.createPool({ const port = source['apollo.mysql.duiba_web_tool.url'].split(':')[1]
// 'host': host, const Mysql = MYSQL.createPool({
// 'port': port, 'host': host,
// 'user': username, 'port': port,
// 'password': password, 'user': username,
// 'database': database, 'password': password,
// 'connectionLimit': 1000 'database': database,
// })
// 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 'connectionLimit': 1000
})
console.info('MysqlConfig:',Mysql.config)
console.info('OBJMysql',Mysql)
resolve(Mysql)
})
}) })
console.info('MysqlConfig:', Mysql.config)
console.info('OBJMysql', Mysql) module.exports = getMysql
module.exports = Mysql
......
const express = require('express') const express = require('express')
const request = require("request"); const request = require("request");
const Mysql = require('../SQLPool') // const Mysql = require('../SQLPool')
const getMysql = require('../SQLPool')
const router = express.Router() const router = express.Router()
getMysql.then(Mysql => {
router.get('/queryType', (req, res) => { router.get('/queryType', (req, res) => {
const SQL = 'SELECT * FROM type' const SQL = 'SELECT * FROM type'
Mysql.query(SQL, (err, result) => { Mysql.query(SQL, (err, result) => {
if (err) { if (err) {
...@@ -17,9 +18,9 @@ router.get('/queryType', (req, res) => { ...@@ -17,9 +18,9 @@ router.get('/queryType', (req, res) => {
data: result data: result
}) })
}) })
}); });
router.get('/queryChildType', (req, res) => { router.get('/queryChildType', (req, res) => {
const {type_id} = req.query 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 = ?' 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) => { Mysql.query(SQL,[type_id], (err, result) => {
...@@ -34,10 +35,10 @@ router.get('/queryChildType', (req, res) => { ...@@ -34,10 +35,10 @@ router.get('/queryChildType', (req, res) => {
data: result data: result
}) })
}) })
}); });
router.get('/queryToolBox', (req, res) => { router.get('/queryToolBox', (req, res) => {
let {isFollow, type_id} = req.query 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 = ?` 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){ if (!isFollow && !type_id){
...@@ -61,7 +62,9 @@ router.get('/queryToolBox', (req, res) => { ...@@ -61,7 +62,9 @@ router.get('/queryToolBox', (req, res) => {
data: result data: result
}) })
}) })
}); });
}).catch(e => console.error(e))
// router.get('/queryToolBoxSortId', (req, res) => { // router.get('/queryToolBoxSortId', (req, res) => {
// const SQL = 'SELECT sortId FROM toolbox' // const SQL = 'SELECT sortId FROM toolbox'
......
const express = require('express'); const express = require('express');
const Mysql = require('../SQLPool')
const router = express.Router(); const router = express.Router();
const getMysql = require('../SQLPool')
const ErrorCode = { const ErrorCode = {
USER_NOT_LOGIN: 70001 USER_NOT_LOGIN: 70001
} }
getMysql.then(Mysql => {
/* GET users listing. */ /* GET users listing. */
router.get('/getUser', function (req, res, next) { router.get('/getUser', function (req, res, next) {
let {uid} = req.cookies let {uid} = req.cookies
if (!uid){ if (!uid){
uid = req.query.uid uid = req.query.uid
...@@ -40,9 +40,9 @@ router.get('/getUser', function (req, res, next) { ...@@ -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 {uid} = req.query
const SQL = 'SELECT * FROM `user` WHERE `user`.uid = ?' const SQL = 'SELECT * FROM `user` WHERE `user`.uid = ?'
Mysql.query(SQL, [uid], (err, result) => { Mysql.query(SQL, [uid], (err, result) => {
...@@ -66,9 +66,9 @@ router.get('/login', (req, res) => { ...@@ -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 {follow, uid} = req.query
const SQL = 'UPDATE user SET follow = ? WHERE uid = ?' const SQL = 'UPDATE user SET follow = ? WHERE uid = ?'
Mysql.query(SQL, [follow, uid], (err, result) => { Mysql.query(SQL, [follow, uid], (err, result) => {
...@@ -83,6 +83,8 @@ router.get('/follow', (req, res) => { ...@@ -83,6 +83,8 @@ router.get('/follow', (req, res) => {
success: true, success: true,
}) })
}) })
})
}).catch(e => {
console.error(e)
}) })
module.exports = router; 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