re-structure web project
This commit is contained in:
parent
a7c11b0671
commit
eb5bca5fb2
|
@ -5,6 +5,8 @@ node_modules
|
||||||
package-lock.json
|
package-lock.json
|
||||||
yarn.lock
|
yarn.lock
|
||||||
coverage/
|
coverage/
|
||||||
|
/web/LICENSE
|
||||||
|
/web/.temp/
|
||||||
.idea/
|
.idea/
|
||||||
run/
|
run/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
@ -22,3 +24,4 @@ docker/.node_modules/*
|
||||||
/data
|
/data
|
||||||
appveyor.yml
|
appveyor.yml
|
||||||
.travis.yml
|
.travis.yml
|
||||||
|
/public
|
25
README.md
25
README.md
|
@ -3,8 +3,9 @@
|
||||||
INFINI Logging Center
|
INFINI Logging Center
|
||||||
|
|
||||||
|
|
||||||
## 开发说明
|
## 前端开发说明
|
||||||
|
|
||||||
|
前端采用 React 开发,最终输出为 `public` 目录的纯静态资源,可以独立部署无需依赖 Node 环境。
|
||||||
|
|
||||||
### Docker 开发环境准备
|
### Docker 开发环境准备
|
||||||
|
|
||||||
|
@ -26,19 +27,13 @@ INFINI Logging Center
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 本地构建开发镜像
|
|
||||||
|
|
||||||
```
|
|
||||||
npm run docker:build
|
|
||||||
```
|
|
||||||
|
|
||||||
#### 启动开发环境
|
#### 启动开发环境
|
||||||
|
|
||||||
```
|
```
|
||||||
cnpm run docker:dev
|
cnpm run docker:dev
|
||||||
```
|
```
|
||||||
|
|
||||||
启动完成,稍等片刻,打开 http://localhost:7001/,手动刷新即可看到最新的更改。
|
启动完成,稍等片刻,打开 http://localhost:8000/,手动刷新即可看到最新的更改。
|
||||||
|
|
||||||
#### 手动更新开发镜像
|
#### 手动更新开发镜像
|
||||||
|
|
||||||
|
@ -75,26 +70,28 @@ cnpm run dev
|
||||||
前端开发:在浏览器中访问:[http://localhost:10000](http://localhost:10000),使用 Mock 接口数据。
|
前端开发:在浏览器中访问:[http://localhost:10000](http://localhost:10000),使用 Mock 接口数据。
|
||||||
|
|
||||||
|
|
||||||
### 构建和部署
|
### 编译静态资源
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
cnpm run build
|
cnpm run build
|
||||||
```
|
```
|
||||||
|
|
||||||
执行该命令后会生成最终的 HTML、CSS 和 JS 到 `app/public` 目录下。它们是浏览器可以直接识别并运行的代码,这样你就可以将它们部署到你想要的服务器上了。
|
执行该命令后会生成最终的 HTML、CSS 和 JS 到 `/public` 目录下。它们是浏览器可以直接识别并运行的代码,这样你就可以将它们部署到你想要的服务器上了。
|
||||||
|
|
||||||
或者使用 Docker 来运行最终的程序。
|
或者使用 Docker 来打包生成。
|
||||||
```
|
```
|
||||||
cnpm run docker:prod
|
cnpm run docker:build
|
||||||
```
|
```
|
||||||
启动完成,稍等片刻,打开 http://localhost:8001/,即可看到最终的程序界面。
|
|
||||||
|
|
||||||
### 新增项目依赖包
|
### 新增项目依赖包
|
||||||
```
|
```
|
||||||
cnpm install --save md5
|
cnpm install --save md5
|
||||||
```
|
```
|
||||||
|
|
||||||
### 启动 MySQL 服务器
|
|
||||||
|
|
||||||
|
## 启动 MySQL 服务器
|
||||||
|
|
||||||
```
|
```
|
||||||
npm run docker:start-mysql
|
npm run docker:start-mysql
|
||||||
```
|
```
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
const Controller = require('egg').Controller;
|
|
||||||
|
|
||||||
class CommandController extends Controller{
|
|
||||||
async exec() {
|
|
||||||
const { ctx, service } = this;
|
|
||||||
const params = {
|
|
||||||
user: { type: 'string' },
|
|
||||||
password: { type: 'string' },
|
|
||||||
host:{ type:'string' },
|
|
||||||
cmd: {type: 'string'},
|
|
||||||
};
|
|
||||||
console.log(ctx.request.body);
|
|
||||||
ctx.validate(params, ctx.request.body);
|
|
||||||
const res = await service.command.exec(ctx.request.body);
|
|
||||||
ctx.body = {data: res};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = CommandController;
|
|
|
@ -1,27 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const Controller = require('egg').Controller;
|
|
||||||
|
|
||||||
class HomeController extends Controller {
|
|
||||||
async index() {
|
|
||||||
if(this.app.config.env == "local") {
|
|
||||||
//TODO remove hardcode
|
|
||||||
this.app.config.assets.url = `http://localhost:10000`;
|
|
||||||
}
|
|
||||||
await this.ctx.render('index.html');
|
|
||||||
}
|
|
||||||
|
|
||||||
async proxy() {
|
|
||||||
const ctx = this.ctx;
|
|
||||||
// use roadhog mock api first
|
|
||||||
const url = this.app.config.assets.url + ctx.path + '?' + ctx.querystring;
|
|
||||||
|
|
||||||
const res = await this.ctx.curl(url, {
|
|
||||||
method: this.ctx.method,
|
|
||||||
});
|
|
||||||
ctx.body = res.data;
|
|
||||||
ctx.status = res.status;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = HomeController;
|
|
|
@ -1,15 +0,0 @@
|
||||||
const os = require('os');
|
|
||||||
module.exports = {
|
|
||||||
getIPAddress() {
|
|
||||||
var interfaces = os.networkInterfaces();
|
|
||||||
for (var devName in interfaces) {
|
|
||||||
var iface = interfaces[devName];
|
|
||||||
for (var i = 0; i < iface.length; i++) {
|
|
||||||
var alias = iface[i];
|
|
||||||
if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
|
|
||||||
return alias.address;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
|
@ -1,11 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {Egg.Application} app - egg application
|
|
||||||
*/
|
|
||||||
module.exports = app => {
|
|
||||||
const { router, controller } = app;
|
|
||||||
router.post('/command/exec', controller.command.exec);
|
|
||||||
router.all('/api/*', controller.home.proxy);
|
|
||||||
router.get('*', controller.home.index);
|
|
||||||
};
|
|
|
@ -1,25 +0,0 @@
|
||||||
const Service = require('egg').Service;
|
|
||||||
var nssh = require('node-ssh');
|
|
||||||
|
|
||||||
class CommandService extends Service{
|
|
||||||
async exec(params){
|
|
||||||
let {host, user, password, port, cmd} = params;
|
|
||||||
port = port || 22;
|
|
||||||
var ssh = new nssh();
|
|
||||||
return ssh.connect({
|
|
||||||
host: host,
|
|
||||||
port: port,
|
|
||||||
username: user,
|
|
||||||
password: password
|
|
||||||
}).then(function(){
|
|
||||||
return ssh.execCommand(cmd, {}).then(function(result) {
|
|
||||||
ssh.dispose();
|
|
||||||
if(result.stderr != ""){
|
|
||||||
return result.stderr;
|
|
||||||
}
|
|
||||||
return result.stdout;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
module.exports = CommandService;
|
|
|
@ -1,27 +0,0 @@
|
||||||
<!doctype html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8" />
|
|
||||||
<meta name="apple-mobile-web-app-capable" content="yes"/>
|
|
||||||
<meta name="apple-mobile-web-app-status-bar-style" content="black"/>
|
|
||||||
<meta name="format-detection" content="telephone=no"/>
|
|
||||||
<meta name="format-detection" content="email=no"/>
|
|
||||||
<link rel="icon" href="/public/favicon.ico" type="image/x-icon">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" />
|
|
||||||
<title></title>
|
|
||||||
{{ helper.assets.getStyle('umi.css') | safe }}
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
<div id="root"></div>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
window.routerBase = '/';
|
|
||||||
window.resourceBaseUrl = '{{ helper.assets.resourceBase }}';
|
|
||||||
</script>
|
|
||||||
{% if ctx.app.config.env === 'local' -%}
|
|
||||||
{{ helper.assets.getScript('umi.dll.js') | safe }}
|
|
||||||
{%- endif %}
|
|
||||||
{{ helper.assets.getScript('umi.js') | safe }}
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -1,38 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
module.exports = appInfo => {
|
|
||||||
const config = exports = {};
|
|
||||||
|
|
||||||
// use for cookie sign key, should change to your own and keep security
|
|
||||||
config.keys = appInfo.name + '_1513765449219_5858';
|
|
||||||
|
|
||||||
config.view = {
|
|
||||||
root: path.join(appInfo.baseDir, 'app/view'),
|
|
||||||
mapping: {
|
|
||||||
'.html': 'nunjucks',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
config.assets = {
|
|
||||||
publicPath: '/public',
|
|
||||||
devServer: {
|
|
||||||
autoPort: true,
|
|
||||||
command: 'umi dev --port={port}',
|
|
||||||
env: {
|
|
||||||
APP_ROOT: path.join(__dirname, '../app/web'),
|
|
||||||
BROWSER: 'none',
|
|
||||||
HMR: 'none',
|
|
||||||
SOCKET_SERVER: 'http://127.0.0.1:{port}',
|
|
||||||
},
|
|
||||||
debug: true,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
config.security = {
|
|
||||||
csrf: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
return config;
|
|
||||||
};
|
|
|
@ -1,16 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
exports.assets = {
|
|
||||||
enable: true,
|
|
||||||
package: 'egg-view-assets',
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.nunjucks = {
|
|
||||||
enable: true,
|
|
||||||
package: 'egg-view-nunjucks',
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.validate = {
|
|
||||||
enable: true,
|
|
||||||
package: 'egg-validate',
|
|
||||||
};
|
|
|
@ -1 +0,0 @@
|
||||||
'use strict';
|
|
|
@ -1,21 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const { app, assert } = require('egg-mock/bootstrap');
|
|
||||||
|
|
||||||
describe('test/app/controller/home.test.js', () => {
|
|
||||||
|
|
||||||
it('should assert', function* () {
|
|
||||||
const pkg = require('../../../package.json');
|
|
||||||
assert(app.config.keys.startsWith(pkg.name));
|
|
||||||
|
|
||||||
// const ctx = app.mockContext({});
|
|
||||||
// yield ctx.service.xx();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should GET /', () => {
|
|
||||||
return app.httpRequest()
|
|
||||||
.get('/')
|
|
||||||
.expect(/<script src="\/umi.js"><\/script>/)
|
|
||||||
.expect(200);
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -105,16 +105,16 @@ export default {
|
||||||
hash: true,
|
hash: true,
|
||||||
outputPath: '../public',
|
outputPath: '../public',
|
||||||
manifest: {
|
manifest: {
|
||||||
fileName: '../../config/manifest.json',
|
fileName: '../public/manifest.json',
|
||||||
publicPath: '',
|
publicPath: '',
|
||||||
},
|
},
|
||||||
|
|
||||||
copy:[
|
copy:[
|
||||||
'../web/src/assets/favicon.ico'
|
'./src/assets/favicon.ico'
|
||||||
],
|
],
|
||||||
history: 'hash',
|
history: 'hash',
|
||||||
exportStatic: {
|
// exportStatic: {
|
||||||
// htmlSuffix: true,
|
// // htmlSuffix: true,
|
||||||
dynamicRoot: true,
|
// dynamicRoot: true,
|
||||||
},
|
// },
|
||||||
};
|
};
|
|
@ -17,13 +17,13 @@ RUN \
|
||||||
|
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
COPY package.json /usr/src/app/
|
#COPY package.json /usr/src/app/
|
||||||
COPY docker/entrypoint.sh /
|
COPY docker/entrypoint.sh /
|
||||||
|
|
||||||
|
|
||||||
RUN npm install --registry=https://registry.npm.taobao.org
|
#RUN npm install --registry=https://registry.npm.taobao.org
|
||||||
|
|
||||||
COPY . /usr/src/app
|
# COPY . /usr/src/app
|
||||||
|
|
||||||
EXPOSE 10000
|
EXPOSE 10000
|
||||||
|
|
|
@ -1,23 +1,23 @@
|
||||||
version: "3.5"
|
version: "3.5"
|
||||||
|
|
||||||
services:
|
services:
|
||||||
infini-logging-release:
|
infini-logging-build:
|
||||||
# option 1: pull image from infini docker registry
|
# option 1: pull image from infini docker registry
|
||||||
image: docker.infini.ltd:64443/nodejs-release:latest
|
image: docker.infini.ltd:64443/nodejs-dev:latest
|
||||||
|
|
||||||
# option 2: build image locally
|
# option 2: build image locally
|
||||||
# build:
|
# build:
|
||||||
# context: ../
|
# context: ../
|
||||||
# dockerfile: docker/Dockerfile
|
# dockerfile: docker/Dockerfile
|
||||||
|
|
||||||
ports:
|
container_name: "infini-nodejs-build"
|
||||||
- 8001:7001
|
|
||||||
container_name: "infini-nodejs-release"
|
|
||||||
volumes:
|
volumes:
|
||||||
- ../app:/usr/src/app/app
|
- ../src:/usr/src/app/src
|
||||||
- ../config:/usr/src/app/config
|
- ../config:/usr/src/app/config
|
||||||
|
- ../mock:/usr/src/app/mock
|
||||||
- ../package.json:/usr/src/app/package.json
|
- ../package.json:/usr/src/app/package.json
|
||||||
- ./entrypoint-release.sh:/entrypoint.sh
|
- ../../public:/usr/src/public
|
||||||
|
- ./entrypoint-build.sh:/entrypoint.sh
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
dist:
|
dist:
|
|
@ -5,22 +5,21 @@ services:
|
||||||
# option 1: pull image from infini docker registry
|
# option 1: pull image from infini docker registry
|
||||||
image: docker.infini.ltd:64443/nodejs-dev:latest
|
image: docker.infini.ltd:64443/nodejs-dev:latest
|
||||||
|
|
||||||
# option 2: build image locally
|
# # option 2: build image locally
|
||||||
# build:
|
# build:
|
||||||
# context: ../
|
# context: ../
|
||||||
# dockerfile: docker/Dockerfile
|
# dockerfile: docker/Dockerfile
|
||||||
|
|
||||||
ports:
|
ports:
|
||||||
- 3000:3000
|
- 3000:3000
|
||||||
- 7001:7001
|
- 8000:8000
|
||||||
- 10000:10000
|
|
||||||
container_name: "infini-nodejs-dev"
|
container_name: "infini-nodejs-dev"
|
||||||
volumes:
|
volumes:
|
||||||
- ../app:/usr/src/app/app
|
- ../src:/usr/src/app/src
|
||||||
- ../config:/usr/src/app/config
|
- ../config:/usr/src/app/config
|
||||||
|
- ../mock:/usr/src/app/mock
|
||||||
- ../package.json:/usr/src/app/package.json
|
- ../package.json:/usr/src/app/package.json
|
||||||
# - ./entrypoint.sh:/entrypoint.sh
|
- ./entrypoint-dev.sh:/entrypoint.sh
|
||||||
# - .node_modules:/usr/src/app/node_modules
|
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
dist:
|
dist:
|
|
@ -6,13 +6,11 @@ npm config set registry http://registry.npm.taobao.org/;
|
||||||
|
|
||||||
cd /usr/src/app
|
cd /usr/src/app
|
||||||
|
|
||||||
echo "START BUILD INFINI-LOGGING-CENTER v1.0"
|
echo "START TO RELEASE INFINI-LOGGING-CENTER"
|
||||||
|
|
||||||
if [ ! -f "$lockPath" ]; then
|
if [ ! -f "$lockPath" ]; then
|
||||||
npm install --registry=https://registry.npm.taobao.org
|
npm install --registry=https://registry.npm.taobao.org
|
||||||
npm run build
|
npm run build
|
||||||
npm run start
|
|
||||||
else
|
else
|
||||||
npm run build
|
npm run build
|
||||||
npm run start
|
|
||||||
fi
|
fi
|
|
@ -6,12 +6,10 @@ npm config set registry http://registry.npm.taobao.org/;
|
||||||
|
|
||||||
cd /usr/src/app
|
cd /usr/src/app
|
||||||
|
|
||||||
echo "START INFINI-LOGGING-CENTER v1.0"
|
echo "START DEBUG INFINI-LOGGING-CENTER"
|
||||||
|
|
||||||
if [ ! -f "$lockPath" ]; then
|
if [ ! -f "$lockPath" ]; then
|
||||||
npm install --registry=https://registry.npm.taobao.org
|
npm install --registry=https://registry.npm.taobao.org
|
||||||
# npm i --production;
|
|
||||||
# npm run autod
|
|
||||||
npm run dev
|
npm run dev
|
||||||
else
|
else
|
||||||
npm run dev
|
npm run dev
|
|
@ -0,0 +1,5 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
npm config set registry http://registry.npm.taobao.org/;
|
||||||
|
cd /usr/src/app
|
||||||
|
echo "INFINI NODEJS ENV READY TO ROCK!"
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "logging-center",
|
"name": "logging-center",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "极限日志分析中心,简单易用。",
|
"description": "极限日志分析中心,致力于简单易用。",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ant-design/icons": "^4.0.0",
|
"@ant-design/icons": "^4.0.0",
|
||||||
|
@ -77,25 +77,12 @@
|
||||||
"node": ">=8.9.0"
|
"node": ">=8.9.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "egg-scripts start --title=infini-logging-center --env prod",
|
"dev": "HOST=0.0.0.0 umi dev",
|
||||||
"stop": "egg-scripts stop --title=infini-logging-center",
|
"build": "umi build",
|
||||||
"dev": "SOCKET_SERVER=none UMI_UI=none egg-bin dev",
|
|
||||||
"local-dev": "egg-bin dev",
|
|
||||||
"debug": "egg-bin debug",
|
|
||||||
"build": "APP_ROOT=$PWD/app/web umi build",
|
|
||||||
"test": "npm run lint -- --fix && npm run test-local",
|
|
||||||
"test-local": "egg-bin test",
|
|
||||||
"cov": "egg-bin cov",
|
|
||||||
"lint": "eslint .",
|
|
||||||
"ci": "npm run lint && npm run cov",
|
|
||||||
"autod": "autod",
|
"autod": "autod",
|
||||||
"sync": "./script/sync.js",
|
"docker:dev": "docker-compose -f ./docker/docker-compose.dev.yml up",
|
||||||
"docker:build-dev-images": "docker-compose -f ./docker/docker-compose.dev.yml build",
|
|
||||||
"docker:dev": "docker-compose -f ./docker/docker-compose.dev.yml up -d",
|
|
||||||
"docker:stop-dev": "docker-compose -f ./docker/docker-compose.dev.yml down",
|
"docker:stop-dev": "docker-compose -f ./docker/docker-compose.dev.yml down",
|
||||||
"docker:build-release-images": "docker-compose -f ./docker/docker-compose.release.yml build",
|
"docker:build": "docker-compose -f ./docker/docker-compose.build.yml up",
|
||||||
"docker:prod": "docker-compose -f ./docker/docker-compose.release.yml up -d",
|
|
||||||
"docker:stop-prod": "docker-compose -f ./docker/docker-compose.release.yml down",
|
|
||||||
"docker:start-mysql": "docker-compose -f ./docker/docker-compose-mysql.dev.yml up -d"
|
"docker:start-mysql": "docker-compose -f ./docker/docker-compose-mysql.dev.yml up -d"
|
||||||
},
|
},
|
||||||
"ci": {
|
"ci": {
|
Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 66 KiB |
Before Width: | Height: | Size: 90 KiB After Width: | Height: | Size: 90 KiB |
Before Width: | Height: | Size: 91 KiB After Width: | Height: | Size: 91 KiB |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue