diff --git a/.gitignore b/.gitignore index 08de578f..4850c8df 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,8 @@ node_modules package-lock.json yarn.lock coverage/ +/web/LICENSE +/web/.temp/ .idea/ run/ .DS_Store @@ -21,4 +23,5 @@ docker/.node_modules/* /data appveyor.yml -.travis.yml \ No newline at end of file +.travis.yml +/public \ No newline at end of file diff --git a/README.md b/README.md index 384b52a0..b20fd5f2 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,9 @@ INFINI Logging Center -## 开发说明 +## 前端开发说明 +前端采用 React 开发,最终输出为 `public` 目录的纯静态资源,可以独立部署无需依赖 Node 环境。 ### Docker 开发环境准备 @@ -26,19 +27,13 @@ INFINI Logging Center } ``` -#### 本地构建开发镜像 - -``` -npm run docker:build -``` - #### 启动开发环境 ``` cnpm run docker:dev ``` -启动完成,稍等片刻,打开 http://localhost:7001/,手动刷新即可看到最新的更改。 +启动完成,稍等片刻,打开 http://localhost:8000/,手动刷新即可看到最新的更改。 #### 手动更新开发镜像 @@ -75,26 +70,28 @@ cnpm run dev 前端开发:在浏览器中访问:[http://localhost:10000](http://localhost:10000),使用 Mock 接口数据。 -### 构建和部署 +### 编译静态资源 ```sh 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 ``` -### 启动 MySQL 服务器 + + +## 启动 MySQL 服务器 + ``` npm run docker:start-mysql ``` diff --git a/app/controller/command.js b/app/controller/command.js deleted file mode 100644 index f7883789..00000000 --- a/app/controller/command.js +++ /dev/null @@ -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; diff --git a/app/controller/home.js b/app/controller/home.js deleted file mode 100644 index 034952e4..00000000 --- a/app/controller/home.js +++ /dev/null @@ -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; diff --git a/app/extend/helper.js b/app/extend/helper.js deleted file mode 100644 index cadea924..00000000 --- a/app/extend/helper.js +++ /dev/null @@ -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; - } - } - } - }, -}; diff --git a/app/router.js b/app/router.js deleted file mode 100644 index 8352f144..00000000 --- a/app/router.js +++ /dev/null @@ -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); -}; diff --git a/app/service/command.js b/app/service/command.js deleted file mode 100644 index 8eed1935..00000000 --- a/app/service/command.js +++ /dev/null @@ -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; diff --git a/app/view/index.html b/app/view/index.html deleted file mode 100644 index 7beaed27..00000000 --- a/app/view/index.html +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - -{{ helper.assets.getStyle('umi.css') | safe }} - - - -
- - -{% if ctx.app.config.env === 'local' -%} -{{ helper.assets.getScript('umi.dll.js') | safe }} -{%- endif %} -{{ helper.assets.getScript('umi.js') | safe }} - - diff --git a/config/config.default.js b/config/config.default.js deleted file mode 100644 index 9d8d3c40..00000000 --- a/config/config.default.js +++ /dev/null @@ -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; -}; diff --git a/config/plugin.js b/config/plugin.js deleted file mode 100644 index 23510dc9..00000000 --- a/config/plugin.js +++ /dev/null @@ -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', -}; diff --git a/script/sync.js b/script/sync.js deleted file mode 100644 index ad9a93a7..00000000 --- a/script/sync.js +++ /dev/null @@ -1 +0,0 @@ -'use strict'; diff --git a/test/app/controller/home.test.js b/test/app/controller/home.test.js deleted file mode 100644 index ad08093c..00000000 --- a/test/app/controller/home.test.js +++ /dev/null @@ -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(/