Commit 8b8aa869 authored by wty's avatar wty

上线前准备

parent 465e3a30
......@@ -24,3 +24,5 @@ yarn-error.log*
/expressServer/node_modules/
/expressServer/.idea/
/.idea
/server/node_modules/
/server/.idea/
......@@ -5,11 +5,11 @@
<excludeFolder url="file://$MODULE_DIR$/temp" />
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
<excludeFolder url="file://$MODULE_DIR$/.idea/inspectionProfiles" />
<excludeFolder url="file://$MODULE_DIR$/server/.idea" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/expressServer/.idea" />
<excludeFolder url="file://$MODULE_DIR$/.idea/inspectionProfiles" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
</module>
......@@ -8,7 +8,7 @@ yarn
rm -rf deploy client/dist
# 打包
yarn build
yarn buildWeb
# 进入server目录并安装依赖
cd server && yarn
......
......@@ -22,7 +22,8 @@
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"build": "sh ./scripts/build.sh",
"buildWeb": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
......
const MYSQL = require('mysql')
const Mysql = MYSQL.createPool({
'host': '127.0.0.1',
'port': '3306',
'user': 'wty',
'password': 'wty990215',
'database': 'dui123',
'connectionLimit': 1000
})
module.exports = Mysql
const express = require('express');
const path = require('path');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
const bodyParser = require('body-parser')
const indexRouter = require('./routes');
const usersRouter = require('./routes/users');
const queryRouter = require('./routes/query')
const addRouter = require('./routes/add')
const deleteRouter = require('./routes/delete')
const updateRouter = require('./routes/update')
const submitRouter = require('./routes/page')
const typeManage = require('./routes/typeManage')
const app = express();
global.domain = 'http://dui123.dui88.com:3000'
const Eureka = require('eureka-node').default
const DockerApp = require('docker-app-node')
const pkg = require('./package.json')
// 获取配置的端口号
const port = 3000
const dockerApp = new DockerApp({
app,
appType: 'express',
port
})
// 注册Eureka
global.eureka = new Eureka({
port, // 应用端口号
appName: pkg.name, // 应用名称
services: ['KJY-WEB'] // 依赖服务名
})
global.eureka.start().then(() => {
dockerApp.startServer()
})
app.use((req, res, next) => {
const url = req.url
const header = {
'Access-Control-Allow-Credentials': true,
'Access-Control-Allow-Origin': req.headers.origin || '*',
'Access-Control-Allow-Headers': 'X-Requested-With,Content-Type',
'Access-Control-Allow-Methods': 'PUT,POST,GET,DEconstE,OPTIONS',
'Content-Type': 'application/json; charset=utf-8'
}
if (url.includes('static')){
header["Content-Type"] = 'text/html; charset=utf-8'
}
//设置相应头
res.set(header)
req.method === 'OPTIONS' ? res.status(204).end() : next()
})
app.use(bodyParser.urlencoded({extended: false}))
app.use(bodyParser.json())
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({extended: false}));
app.use(cookieParser());
app.use('/static', express.static(path.join(__dirname, 'static')));
app.use('/', indexRouter);
app.use('/users', usersRouter);
app.use('/query', queryRouter)
app.use('/add', addRouter)
app.use('/delete', deleteRouter)
app.use('/update', updateRouter)
app.use('/page', submitRouter)
app.use('/typeManage', typeManage)
module.exports = app;
#!/usr/bin/env node
/**
* Module dependencies.
*/
let app = require('../app');
let debug = require('debug')('expressserver:server');
let http = require('http');
/**
* Get port from environment and store in Express.
*/
let port = normalizePort(process.env.PORT || '3001');
app.set('port', port);
/**
* Create HTTP server.
*/
let server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
/**
* Normalize a port into a number, string, or false.
*/
function normalizePort(val) {
let port = parseInt(val, 10);
if (isNaN(port)) {
// named pipe
return val;
}
if (port >= 0) {
// port number
return port;
}
return false;
}
/**
* Event listener for HTTP server "error" event.
*/
function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}
let bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}
/**
* Event listener for HTTP server "listening" event.
*/
function onListening() {
let addr = server.address();
let bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}
This diff is collapsed.
{
"name": "expressserver",
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "nodemon bin/www",
"start": "node bin/www"
},
"dependencies": {
"@types/express": "^4.17.13",
"@types/mysql": "^2.15.19",
"body-parse": "^0.1.0",
"body-parser": "^1.19.0",
"cookie-parser": "~1.4.4",
"debug": "~2.6.9",
"docker-app-node": "^0.0.1",
"eureka-node": "^0.3.9",
"express": "~4.16.1",
"morgan": "~1.9.1",
"mysql": "^2.18.1",
"nodemon": "^2.0.12",
"pm2": "^5.1.2",
"request": "^2.88.2"
}
}
const express = require('express')
const request = require("request");
const Mysql = require("../SQLPool");
const router = express.Router()
router.get('/addToolBox', (req, res) => {
const {toolBoxName, toolBoxIcon, toolBoxDesc, toolBoxUrl, typeId, childTypeId} = req.query
const SQL = 'INSERT INTO toolbox (toolBoxName, toolBoxIcon, toolBoxDesc, toolBoxUrl,sortId) VALUES (?,?,?,?,?)'
Mysql.query(SQL, [toolBoxName, toolBoxDesc, toolBoxIcon, toolBoxUrl, 0], (err, result) => {
if (err) {
res.send({
success: false,
err
})
return
}
request(domain + '/query/queryToolBox', {}, (a, b, body) => {
const data = JSON.parse(body).data
const lastToolBoxId = data[data.length - 1].toolBoxId
const SQL = 'INSERT INTO type_childtype_toolbox (toolBoxId,typeId,childTypeId) VALUES (?,?,?)'
Mysql.query(SQL, [lastToolBoxId,typeId,childTypeId], (err, result) => {
if (err) {
res.send({
success: false,
err
})
return
}
res.send({
success: true
})
})
})
})
})
router.get('/addType', (req, res) => {
const {typeName, childTypeName, typeId} = req.query
console.log(req.query)
let SQL = 'INSERT INTO type (typeName) VALUES (?)'
const values = []
if (childTypeName && typeId) {
SQL = 'INSERT INTO child_type (childTypeName, typeId) VALUES (?,?)'
values.push(childTypeName)
values.push(typeId)
} else {
values.push(typeName)
}
console.log(values)
try {
Mysql.query(SQL, values, (err, result) => {
if (err) {
res.send({
success: false,
err
})
throw err
}
res.send({
success: true,
data: result
})
})
} catch (e) {
console.error(e)
}
})
module.exports = router
const express = require('express')
const request = require('request')
const Mysql = require("../SQLPool");
const router = express.Router()
router.get('/deleteToolBoxById', (req, res) => {
const {toolBoxId} = req.query
const SQL = 'DELETE FROM toolbox WHERE toolBoxId = ?'
try {
Mysql.query(SQL, [toolBoxId], (err, result) => {
if (err) {
res.send({
success: false,
err
})
throw err
}
res.send({
success: true,
data: result
})
})
}catch (e){
console.error(e)
}
})
module.exports = router
let express = require('express');
const request = require('request')
let router = express.Router();
/* GET home page. */
module.exports = router;
const express = require('express');
const Mysql = require('../SQLPool')
const fs = require("fs");
const request = require("request");
const path = require("path");
const router = express.Router();
router.post('/addPage', (req, res) => {
const {pageName, code} = req.body
const SQL = `INSERT INTO page (pageName) VALUES (?)`
Mysql.query(SQL, [pageName], (err, result) => {
if (err) {
res.send({
success: false,
error: err
})
} else {
const a = [{
typeId: 1,
}]
try {
request(domain + '/page/queryPage', {}, (a, b, body) => {
const data = JSON.parse(body).data
const id = data[data.length - 1]['pageId']
const fileName = 'page' + id + '.html'
try {
console.log('path:', path.join(__dirname, '../static/' + fileName))
fs.writeFileSync(path.join(__dirname, '../static/' + fileName), code)
res.send({
success: true
})
} catch (e) {
res.send({
success: false,
error: e
})
console.error(e)
}
})
} catch (e) {
console.error(e)
res.send({
success: false,
error: e
})
}
}
})
})
router.get('/queryPage', (req, res) => {
const SQL = 'SELECT * FROM page'
Mysql.query(SQL, [], (err, result) => {
if (err) {
res.send({
success: false,
err
})
}
const _result = result.map(v => {
const url = 'http://172.16.130.180:3001/static/' + 'page' + v['pageId'] + '.html'
return {
...v,
pageUrl: url
}
})
res.send({
success: true,
data: _result
})
})
})
router.post('/updatePage', (req, res) => {
const {pageId, pageName, code} = req.body
const SQL = 'UPDATE page SET pageName=? WHERE pageId = ?'
Mysql.query(SQL, [pageName, pageId], (err, result) => {
if (err) {
res.send({
success: false,
error: err
})
} else {
try{
const fileName = 'page' + pageId + '.html'
fs.writeFileSync(path.join(__dirname, '../static/' + fileName), code)
res.send({
success: true
})
}catch (e){
res.send({
success: false,
error: e
})
}
}
})
})
module.exports = router
const express = require('express')
const request = require("request");
const Mysql = require('../SQLPool')
const router = express.Router()
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: true,
data: result
})
})
});
router.get('/queryChildType', (req, res) => {
const {typeId} = req.query
const SQL = 'SELECT child_type.childTypeId, child_type.childTypeName, child_type.typeId FROM child_type INNER JOIN type ON child_type.typeId = type.typeId WHERE type.typeId = ?'
Mysql.query(SQL,[typeId], (err, result) => {
if (err) {
res.send({
success: false,
err
})
}
res.send({
success: true,
data: result
})
})
});
router.get('/queryToolBox', (req, res) => {
let {isFollow, typeId} = req.query
let SQL = `SELECT toolbox.*, type_childtype_toolbox.childTypeId FROM type_childtype_toolbox INNER JOIN toolbox ON type_childtype_toolbox.toolBoxId = toolbox.toolBoxId WHERE type_childtype_toolbox.typeId = ?`
if (!isFollow && !typeId){
SQL = `SELECT * FROM toolBox`
}
if (isFollow) {
typeId = JSON.parse(typeId)
SQL = 'SELECT * FROM toolbox WHERE toolboxId IN (?)'
}
Mysql.query(SQL, [typeId], (err, result) => {
if (err) {
res.send({
success: false,
err
})
throw err
}
res.send({
success: true,
data: result
})
})
});
// router.get('/queryToolBoxSortId', (req, res) => {
// const SQL = 'SELECT sortId FROM toolBox'
// Mysql.query(SQL, (err, result) => {
// if (err) {
// res.send({
// success: false,
// err
// })
// throw err
// }
// const _result = []
// result.map(v => _result.push(v["sortId"]))
// res.send({
// success: true,
// data: _result.sort((a, b) => a - b)
// })
// })
// })
module.exports = router
const express = require('express')
const router = express.Router()
router.get('/', (req, res) => {
res.set({
'Content-Type': 'text/html; charset=utf-8'
})
})
module.exports = router
const express = require('express')
const request = require("request");
const Mysql = require('../SQLPool')
const router = express.Router()
router.get('/queryType', (req, res) => {
const SQL = 'SELECT * FROM type'
Mysql.query(SQL, (err, result) => {
if (err) {
res.send({
success: false,
err
})
return
}
res.send({
success: true,
data: result
})
})
})
router.get('/queryChildType', (req, res) => {
const SQL = 'SELECT * FROM child_type'
Mysql.query(SQL, (err, result) => {
if (err) {
res.send({
success: false,
err
})
return
}
res.send({
success: true,
data: result
})
})
})
router.get('/queryTypeForManage', (req, res) => {
const SQL = 'SELECT child_type.childTypeId, child_type.childTypeName, child_type.typeId, type.typeName FROM child_type INNER JOIN type ON child_type.typeId = type.typeId'
Mysql.query(SQL, [], (err, result) => {
const dataArr = []
const combineType = (value) => {
if (dataArr.filter(v => v.typeId === value.typeId).length) return
const childType = result.filter(v => v.typeId === value.typeId).map(v => ({
childTypeId: v.childTypeId,
childTypeName: v.childTypeName
}))
dataArr.push({
typeId: value.typeId,
typeName: value.typeName,
children: childType
})
}
result.forEach(v => {
combineType(v)
})
res.send({
success: true,
data: dataArr
})
})
})
router.get('/deleteChildType', ((req, res) => {
const {childTypeId} = req.query
let SQL = 'DELETE FROM child_type WHERE childTypeId = ?;'
let SQL2 = 'DELETE FROM type_childtype_toolbox WHERE childTypeId = ?;'
Mysql.query(SQL, [childTypeId], (err, result) => {
if (err) {
res.send({
success: false,
err
})
return
}
Mysql.query(SQL2, [childTypeId], (err, result) => {
res.send({
success: true,
})
})
})
}))
router.get('/updateType', (req, res) => {
const {typeId, typeName, childTypeId, childTypeName} = req.query
let SQL
const values = []
if (typeId) {
SQL = 'UPDATE type SET typeName = ? WHERE typeId = ?'
values.push(typeName)
values.push(typeId)
} else {
SQL = 'UPDATE child_type SET childTypeName = ? WHERE childTypeId = ?'
values.push(childTypeName)
values.push(childTypeId)
}
Mysql.query(SQL, values, (err, result) => {
if (err) {
res.send({
success: false,
err
})
return
}
res.send({
success: true,
})
})
})
module.exports = router
const express = require('express')
const router = express.Router()
const Mysql = require('../SQLPool')
router.get('/updateToolBox', (req, res) => {
const {toolBoxName, toolBoxIcon, toolBoxUrl, toolBoxDesc, toolBoxId} = req.query
const SQL = 'UPDATE toolbox SET toolBoxName= ?, toolBoxIcon=?, toolBoxUrl=?, toolBoxDesc=? WHERE toolBoxId = ?'
Mysql.query(SQL, [toolBoxName, toolBoxIcon, toolBoxUrl, toolBoxDesc, toolBoxId], (err, result) => {
if (err) {
res.send({
success: false,
err
})
}
res.send({
success: true,
data: result
})
})
})
router.get('/updateToolBoxSort',(req, res) => {
const {sortArr} = req.query
console.log(sortArr)
res.send({
success: true,
data: sortArr
})
})
router.get('/updateChildType', (req, res) => {
const childrenTypeArr = [{id: 1, name: '运营'},{id: 2, name: '测试'},]
const SQL = 'UPDATE type SET typeContent = ? WHERE typeId = 2'
try {
Mysql.query(SQL, [JSON.stringify(childrenTypeArr)], (err, result) => {
if (err) {
res.send({
success: false,
err
})
throw err
}
res.send({
success: true,
data: result
})
})
} catch (e) {
console.error(e)
}
})
module.exports = router
const express = require('express');
const Mysql = require('../SQLPool')
const router = express.Router();
const ErrorCode = {
USER_NOT_LOGIN: 70001
}
/* GET users listing. */
router.get('/getUser', function (req, res, next) {
let {userId} = req.cookies
if (!userId){
userId = req.query.userId
}
// if (!userId) {
// res.send({
// success: false,
// code: ErrorCode.USER_NOT_LOGIN,
// data: '用户尚未登录'
// })
// return
// }
const SQL = 'SELECT * FROM `user` WHERE `user`.uid = ?'
Mysql.query(SQL, [userId], (err, result) => {
if (err) {
res.send({
success: false,
err
})
return
}
const _result = result.slice()
_result[0].follow = JSON.parse(_result[0].follow)
// console.log(JSON.parse(_result[0]))
res.send({
success: true,
data: {
..._result[0],
}
})
})
});
router.get('/login', (req, res) => {
const {userId} = req.query
const SQL = 'SELECT * FROM `user` WHERE `user`.uid = ?'
Mysql.query(SQL, [userId], (err, result) => {
if (err) {
res.send({
success: false,
err
})
throw err
}
if (result[0]?.uid) {
res.cookie('userId', result[0].uid)
res.send({
success: true,
data: '登录成功!'
})
} else {
res.send({
success: false,
data: '登录失败,用户不存在'
})
}
})
})
router.get('/follow', (req, res) => {
const {follow, userId} = req.query
const SQL = 'UPDATE user SET follow = ? WHERE uid = ?'
Mysql.query(SQL, [follow, userId], (err, result) => {
if (err) {
res.send({
success: false,
err
})
return
}
res.send({
success: true,
})
})
})
module.exports = router;
This diff is collapsed.
const apiConfig = {
domain: 'http://' + '172.16.130.180' + ':3001',
domain: 'http://' + location.hostname + ':3000',
}
export default apiConfig
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