diff --git a/client/components/Footer/Footer.js b/client/components/Footer/Footer.js index 5fabea62..a50fe4e1 100644 --- a/client/components/Footer/Footer.js +++ b/client/components/Footer/Footer.js @@ -43,9 +43,9 @@ class FootItem extends Component { render () { return (
-

{ this.props.title }

+

   { this.props.title }

{ this.props.linkList.map(function(item,i){ - return (
{ item.itemTitle }
); + return (
  { item.itemTitle }
); }) }
); diff --git a/client/components/Footer/Footer.scss b/client/components/Footer/Footer.scss index 521e2e6d..17e34b76 100644 --- a/client/components/Footer/Footer.scss +++ b/client/components/Footer/Footer.scss @@ -2,7 +2,7 @@ @import '../../styles/mixin.scss'; .footer{ - // max-width: 12rem; + @include wrap-width-limit; margin: 0px auto; clear: both; font-size: 12px; @@ -48,7 +48,7 @@ } a{ font-weight: 200; - color: #108ee9; + color: #b3bdc1; &:hover{ color: white; } diff --git a/client/components/Header/Header.js b/client/components/Header/Header.js index e5b8afb3..84ed268d 100644 --- a/client/components/Header/Header.js +++ b/client/components/Header/Header.js @@ -146,15 +146,19 @@ export default class HeaderCom extends Component { } render () { const { login, user, msg, uid, curKey } = this.props; - const headerStyle = { + const headerImgStyle = login?{}:{ 'background': 'url(./image/header-bg-img.jpg) no-repeat', 'backgroundSize':'100% 100%' - } + }; + const headerShadeStyle = login? { + 'padding':'0' + }: { + 'background': 'linear-gradient(to bottom,rgba(0,0,0,0.6),rgba(0,0,0,0.5))', + 'padding':'0' + }; return ( - -
+ +
YAPI diff --git a/client/components/Header/Header.scss b/client/components/Header/Header.scss index 0c478555..b05bb82f 100644 --- a/client/components/Header/Header.scss +++ b/client/components/Header/Header.scss @@ -7,20 +7,11 @@ $color-blue-deeper: #34495E; $color-grey-deep : #929aac; $color-black-light : #404040; /* .header-box.css */ - -//.light{ -// background-color: #f7fafc; -// color: $color-blue; -//} -//.dark { -// background-color: $color-black-light; -// color: $color-white; -//} .header-box { display: block; font-size: 0.14rem; z-index: 99; - // 内容宽度 + @include wrap-width-limit; .content { @include row-width-limit; margin: 0 auto; diff --git a/client/components/Intro/Intro.scss b/client/components/Intro/Intro.scss index a4c3d334..204f2e38 100644 --- a/client/components/Intro/Intro.scss +++ b/client/components/Intro/Intro.scss @@ -52,6 +52,8 @@ $color-white: #fff; } } .img-container{ + height: 100%; + width: 100%; padding-right: .15rem; //background-image: url("#{$imgUrl}demo-img.png"); img{ diff --git a/client/containers/AddInterface/InterfaceTest/InterfaceTest.js b/client/containers/AddInterface/InterfaceTest/InterfaceTest.js index 8a6f8df1..cd2230f7 100644 --- a/client/containers/AddInterface/InterfaceTest/InterfaceTest.js +++ b/client/containers/AddInterface/InterfaceTest/InterfaceTest.js @@ -1,7 +1,7 @@ import React, { Component } from 'react' import PropTypes from 'prop-types' import { connect } from 'react-redux' -import { Button, Input, Select, Card } from 'antd' +import { Button, Input, Select, Card, Alert } from 'antd' import { autobind } from 'core-decorators'; import crossRequest from 'cross-request'; import { withRouter } from 'react-router'; @@ -167,6 +167,10 @@ export default class InterfaceTest extends Component { this.setState({ params }); } + hasCrossRequestPlugin() { + const dom = document.getElementById('y-request'); + return dom.getAttribute('key') === 'yapi'; + } render () { @@ -175,10 +179,29 @@ export default class InterfaceTest extends Component { const search = URL.format({ query }); + const hasPlugin = this.hasCrossRequestPlugin(); return (
+
+ { hasPlugin ? '' : + + 温馨提示:当前正在使用接口测试服务,请安装我们为您免费提供的  + + 测试增强插件 [点击获取]! + +
+ } + type="warning" + /> + } +
{interfaceName}
diff --git a/client/containers/Home/Home.scss b/client/containers/Home/Home.scss index f62eb0f6..5ad5c9d9 100644 --- a/client/containers/Home/Home.scss +++ b/client/containers/Home/Home.scss @@ -12,9 +12,10 @@ $color-black-lighter: #404040; display: -webkit-box; -webkit-box-orient: vertical; .main-one{ + @include wrap-width-limit; .home-des{ color: $color-blue-grey-lighter; - padding: .5rem 0 0; + padding: .4rem 0 0; .title{ font-size: .6rem; } @@ -26,7 +27,7 @@ $color-black-lighter: #404040; color: $color-white; } .img-container{ - margin-bottom: -.2rem; + margin-bottom: -.3rem; img{ width: 100%; height: 100%; @@ -75,6 +76,7 @@ $color-black-lighter: #404040; .main-part{ padding: .9rem .5rem; height: 5.8rem; + @include wrap-width-limit; &:nth-child(odd){ background-color: $color-blue-lighter; } @@ -83,6 +85,7 @@ $color-black-lighter: #404040; } } .feat-part{ + @include wrap-width-limit; padding: .9rem .5rem; background-color: $color-white; p{ diff --git a/client/containers/ProjectGroups/GroupList/GroupList.scss b/client/containers/ProjectGroups/GroupList/GroupList.scss index 68902b46..7db3c95f 100644 --- a/client/containers/ProjectGroups/GroupList/GroupList.scss +++ b/client/containers/ProjectGroups/GroupList/GroupList.scss @@ -37,14 +37,15 @@ } .group-operate { height: 48px; - min-width: 263px; padding: 10px 6px; background: #eee; + display: flex; + justify-content: space-around; .search { - display: inline-block; margin-right: 6px; - width: 162px; + flex-grow: 1; } + } .group-list { max-height: 650px; diff --git a/client/containers/User/Profile.js b/client/containers/User/Profile.js index b8de8a2e..3a256867 100644 --- a/client/containers/User/Profile.js +++ b/client/containers/User/Profile.js @@ -138,8 +138,8 @@ class Profile extends Component { userNameEditHtml =
- - + +
} @@ -154,8 +154,8 @@ class Profile extends Component { emailEditHtml =
- - + +
} @@ -175,15 +175,15 @@ class Profile extends Component { } if (this.state.secureEdit === false) { - secureEditHtml = + secureEditHtml = } else { secureEditHtml =
- - + +
} @@ -228,7 +228,7 @@ class Profile extends Component { - 安全 + 密码 {secureEditHtml} diff --git a/client/containers/User/index.scss b/client/containers/User/index.scss index c93cb420..f0aaf0e9 100644 --- a/client/containers/User/index.scss +++ b/client/containers/User/index.scss @@ -24,15 +24,22 @@ border-radius:5px; margin-top: 15px; .search{ - margin: 5px; + padding: 5px; + background-color: #eee; } ul{border:none} + .ant-menu-item{ + font-size: 14px; + } } .user-name{ - padding: 10px 0px; + padding: 24px 0px; text-align: center; background-color: #34495e; color: white; + font-size: 16px; + border-top-left-radius:5px; + border-top-right-radius: 5px; span{ margin-right: 10px; } @@ -62,17 +69,27 @@ -webkit-box-flex: 1; margin-top: 15px; margin-left: 15px; - padding: 10px 30px; + padding: 24px; box-shadow: 0 2px 4px 0 rgba(0,0,0,0.20); background: #FFF; border-radius:5px; + .ant-btn-group{ + margin-top: 12px; + } .user-item { min-height:35px; line-height:35px; margin: 5px; + margin-left: 0px; margin-bottom:10px; border-bottom: 1px solid #f1f3f6; padding-bottom: 10px; + #old_password,#password,#verify_pass{ + margin-top: 20px; + } + #old_password{ + margin-top: 0px; + } .ant-col-4{ color: black; padding: 0px 10px; @@ -90,13 +107,13 @@ cursor: pointer } - .edit-buttons{ - margin:10px; - } + // .edit-buttons{ + // margin:10px; + // } - .edit-button{ - margin: 5px; - } + // .edit-button{ + // margin: 5px; + // } } } diff --git a/client/styles/mixin.scss b/client/styles/mixin.scss index 0489cf44..c94c2eb9 100644 --- a/client/styles/mixin.scss +++ b/client/styles/mixin.scss @@ -2,3 +2,7 @@ max-width: 11.7rem; min-width: 9.7rem; } + +@mixin wrap-width-limit { + min-width: 10.7rem; +} diff --git a/config_example.json b/config_example.json new file mode 100644 index 00000000..14164abc --- /dev/null +++ b/config_example.json @@ -0,0 +1,21 @@ +{ + "port": "3000", + "webhost": "yapi.local.qunar.com", + "adminAccount": "admin@admin.com", + "db": { + "servername": "127.0.0.1", + "DATABASE": "yapi", + "port": 27017, + "user": "test1", + "pass": "test1" + }, + "mail": { + "host": "smtp.163.com", + "port": 465, + "from": "***@163.com", + "auth": { + "user": "***@163.com", + "pass": "*****" + } + } +} \ No newline at end of file diff --git a/doc/api_doc.md b/doc/api_doc.md deleted file mode 100644 index e9765d3a..00000000 --- a/doc/api_doc.md +++ /dev/null @@ -1,35 +0,0 @@ -### 1.User -- /user/get //获取用户个人信息 -- /user/list //获取用户列表,需要提供分页功能 -- /user/del //删除用户 -- /user/up //更新用户个人信息 -- /uesr/login //登录 -- /user/reg //注册 -- /user/login/status //获取用户登录状态 - -### 2.Group -- /group/list //获取项目分组列表 -- /group/add //添加 -- /group/up //更新 -- /group/del //删除 - -### 3.Project -- /project/list/:group_id -- /project/add //添加项目 -- /project/up //编辑项目 -- /project/del //删除项目 -- /project/add_member //添加项目成员 -- /project/del_member //删除项目成员 -- /project/get //获取一个项目详细信息 - - - -### 4.interface -- /interface/list/:project_id -- /interface/add -- /interface/up -- /interface/del -- /interface/mock //执行用户定义的mock,返回mock结果 - -### 5. mock服务器 -用户修改host指到yapi服务器,yapi服务器收到请求后根据domain/basepath 找到相对应的项目,根据req信息,找到对应的接口,执行用户定义的mock数据,返回给用户相应的结果 diff --git a/doc/db_dict.md b/doc/db_dict.md deleted file mode 100644 index 9c3a747a..00000000 --- a/doc/db_dict.md +++ /dev/null @@ -1,93 +0,0 @@ -### 数据库字典 -### 数据库基于mongodb -#### 1.User数据表,表名:user -```json -{ - _id: (int) - username: (string) - password: (sha1) - passsalt: (string) - email : (string) - role : (string) - add_time: (int) - up_time: (int) -} -```` - -#### 2.Project 数据表,表名:project -```json -{ - _id: (int) - uid : (int) - name: (string) - basepath: (string) - desc: (string) - group_id: (int) - members: [ - ... //成员uid - ] - prd_host: (string)//网站上线的domain,可用来获取mock数据 - env:(object){ - 'local环境' : 'http://127.0.0.1' - } - add_time: (int) - up_time: (int) -} -```` - -#### 3.api 数据表,表名:interface -```json -{ - _id: (int) - uid: (int) //负责人uid - path: (string) - group_id: (int) - status: (int) - desc : (string) - add_time: (int) - up_time : (int) - req_headers:(Object){ - "header_name":(Object){ - default_value: (string), - desc: (string), - mock: (string) - } - } - req_params_type: (form|raw) - req_params: (Object){ - "key" : (Object){ - default_value: (string), - desc: (string), - mock: (string) - } - } - res_header: (Object){ - "header_name":(Object){ - default_value: (string), - desc: (string), - mock: (string) - } - } - res_body_type: (text|json), - res_body: (Object){ - "key":(Object){ - default_value: (string), - desc: (string), - mock: (string) - } - } -} - -``` - -#### 4.项目分组,表名: group -```json -{ - _id: (int), - uid: (int), - group_name: (string), - group_desc: (string), - add_time: (int), - up_time: (int) -} -``` diff --git a/gulpfile.js b/gulpfile.js index 7f79ee0e..196cc5c6 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -12,14 +12,14 @@ const SRC = 'server/**/*.js'; function generateBabel(status) { const babelProcess = babel({ - presets: ['es2015', "stage-3"], + presets: ['es2015', 'stage-3'], plugins: ['transform-runtime'] }); babelProcess.on('error', function (e) { const restart = status ? status.count < 2 : true; - console.error(e); + console.error(e); // eslint-disable-line output('error', 'babel 编译失败!', restart); if (status) { @@ -39,7 +39,13 @@ function excuteCmd(cmd, args, opts) { }); command.stderr.on('data', data => { - output('log', `${NAME} ${data.toString()}`, true); + const message = data.toString(); + + output('log', `${NAME} ${message}`, true); + + if (~message.indexOf('building complete')) { + waitingSpinner(); + } }); return command; @@ -50,12 +56,12 @@ function output(type, message, restart = false) { if (type === 'success') { message = '✔ ' + message; - console.log(chalk.green(message)); + console.log(chalk.green(message)); // eslint-disable-line } else if (type === 'error') { message = '✖ ' + message; - console.log(chalk.red(message)); + console.log(chalk.red(message)); // eslint-disable-line } else { - console.log(message); + console.log(message); // eslint-disable-line } if (restart) { spinner.start(); @@ -63,6 +69,7 @@ function output(type, message, restart = false) { } function waitingSpinner() { + spinner.stop(); spinner = ora({ text: '等待文件变更...', spinner: 'circleQuarters', @@ -71,7 +78,7 @@ function waitingSpinner() { } gulp.task('removeDist', [], function () { - return fs.removeSync(DIST) + return fs.removeSync(DIST); }); gulp.task('initialBuild', ['removeDist'], () => { @@ -95,9 +102,14 @@ gulp.task('initialBuild', ['removeDist'], () => { }); gulp.task('default', ['initialBuild'], () => { - gulp.watch(SRC, (event) => { - let originFilePath = path.relative(path.join(__dirname, 'server'), event.path) - let distPath = path.resolve(DIST, path.join(originFilePath)) + gulp.watch('client/**/*', event => { + spinner.stop(); + spinner = ora(`正在编译 ${event.path}`).start(); + }); + + gulp.watch(SRC, event => { + let originFilePath = path.relative(path.join(__dirname, 'server'), event.path); + let distPath = path.resolve(DIST, path.join(originFilePath)); spinner.text = `正在编译 ${event.path}...`; gulp.src(event.path).pipe(generateBabel()) diff --git a/server/config.js b/server/config.js deleted file mode 100644 index 65a6b153..00000000 --- a/server/config.js +++ /dev/null @@ -1,18 +0,0 @@ -module.exports = { - 'port': '3000', - 'webhost': 'yapi.local.qunar.com', - 'adminAccount': 'admin@admin.com', - 'db': { - 'servername': '127.0.0.1', - 'DATABASE': 'yapi', - 'port': 27017 - }, - 'mail': { - 'host': 'smtp.mail.com', - 'port': 4652, - 'auth': { - 'user': '****@mail.com', - 'pass': '**********' - } - } -}; \ No newline at end of file diff --git a/server/controllers/base.js b/server/controllers/base.js index b8b2b3d2..876eee35 100644 --- a/server/controllers/base.js +++ b/server/controllers/base.js @@ -1,20 +1,19 @@ -import yapi from '../yapi.js' -import projectModel from '../models/project.js' -import userModel from '../models/user.js' +import yapi from '../yapi.js'; +import projectModel from '../models/project.js'; +import userModel from '../models/user.js'; const jwt = require('jsonwebtoken'); - -class baseController{ - constructor(ctx){ +class baseController { + constructor(ctx) { this.ctx = ctx; //网站上线后,role对象key是不能修改的,value可以修改 this.roles = { admin: 'Admin', member: '网站会员' - } + }; } - async init(ctx){ + async init(ctx) { this.$user = null; let ignoreRouter = [ '/user/login_by_token', @@ -22,73 +21,93 @@ class baseController{ '/user/reg', '/user/status', '/user/logout' - ] - if(ignoreRouter.indexOf(ctx.path) > -1){ + ]; + if (ignoreRouter.indexOf(ctx.path) > -1) { this.$auth = true; - }else{ - await this.checkLogin(ctx) + } else { + await this.checkLogin(ctx); } - + } - getUid(ctx){ + getUid() { return parseInt(this.$uid, 10); } - async checkLogin(ctx){ + async checkLogin(ctx) { let token = ctx.cookies.get('_yapi_token'); - let uid = ctx.cookies.get('_yapi_uid'); - try{ - if(!token || !uid) return false; + let uid = ctx.cookies.get('_yapi_uid'); + + try { + if (!token || !uid) return false; let userInst = yapi.getInst(userModel); //创建user实体 let result = await userInst.findById(uid); - let decoded = jwt.verify(token, result.passsalt) - if(decoded.uid == uid){ + let decoded = jwt.verify(token, result.passsalt); + + if (decoded.uid == uid) { this.$uid = uid; this.$auth = true; - this.$user = result; + this.$user = result; return true; } + return false; - }catch(e){ + } catch (e) { return false; } } - async getLoginStatus(ctx){ - if(await this.checkLogin(ctx) === true){ - return ctx.body = yapi.commons.resReturn(yapi.commons.fieldSelect(this.$user,['_id','username','email', 'up_time', 'add_time'])); + async getLoginStatus(ctx) { + if (await this.checkLogin(ctx) === true) { + return ctx.body = yapi.commons.resReturn(yapi.commons.fieldSelect(this.$user, ['_id', 'username', 'email', 'up_time', 'add_time'])); } - return ctx.body = yapi.commons.resReturn(null, 300 , 'Please login.'); - + return ctx.body = yapi.commons.resReturn(null, 300, 'Please login.'); } - getRole(){ + getRole() { return this.$user.role; } - async jungeProjectAuth(id){ + async jungeProjectAuth(id) { let model = yapi.getInst(projectModel); - if(this.getRole() === 'admin') return true; - if(!id) return false; - let result = await model.get(id); - if(result.uid === this.getUid()){ + + if (this.getRole() === 'admin') { return true; } + + if (!id) { + return false; + } + + let result = await model.get(id); + + if (result.uid === this.getUid()) { + return true; + } + return false; } - async jungeMemberAuth(id, member_uid){ + async jungeMemberAuth(id, member_uid) { let model = yapi.getInst(projectModel); - if(this.getRole() === 'admin') return true; - if(!id || !member_uid) return false; - let result = await model.checkMemberRepeat(id, member_uid); - if(result > 0){ + + if (this.getRole() === 'admin') { return true; } + + if (!id || !member_uid) { + return false; + } + + let result = await model.checkMemberRepeat(id, member_uid); + + if (result > 0) { + return true; + } + return false; } } -module.exports = baseController \ No newline at end of file +module.exports = baseController; \ No newline at end of file diff --git a/server/controllers/group.js b/server/controllers/group.js index 9dbb7db0..47aac602 100644 --- a/server/controllers/group.js +++ b/server/controllers/group.js @@ -1,14 +1,12 @@ -import groupModel from '../models/group.js' -import yapi from '../yapi.js' -import baseController from './base.js' -import projectModel from '../models/project.js' +import groupModel from '../models/group.js'; +import yapi from '../yapi.js'; +import baseController from './base.js'; +import projectModel from '../models/project.js'; -// -class groupController extends baseController{ - constructor(ctx){ - super(ctx) +class groupController extends baseController { + constructor(ctx) { + super(ctx); } - /** * 添加项目分组 @@ -23,37 +21,45 @@ class groupController extends baseController{ */ async add(ctx) { let params = ctx.request.body; + params = yapi.commons.handleParams(params, { group_name: 'string', group_desc: 'string' - }) - if(this.getRole() !== 'admin'){ - return ctx.body = yapi.commons.resReturn(null,401,'没有权限'); + }); + + if (this.getRole() !== 'admin') { + return ctx.body = yapi.commons.resReturn(null, 401, '没有权限'); } - if(!params.group_name){ + + if (!params.group_name) { return ctx.body = yapi.commons.resReturn(null, 400, '项目分组名不能为空'); } - var groupInst = yapi.getInst(groupModel); - - var checkRepeat = await groupInst.checkRepeat(params.group_name); - if(checkRepeat > 0){ - return ctx.body = yapi.commons.resReturn(null, 401, '项目分组名已存在'); + + let groupInst = yapi.getInst(groupModel); + + let checkRepeat = await groupInst.checkRepeat(params.group_name); + + if (checkRepeat > 0) { + return ctx.body = yapi.commons.resReturn(null, 401, '项目分组名已存在'); } + let data = { group_name: params.group_name, group_desc: params.group_desc, uid: this.getUid(), add_time: yapi.commons.time(), up_time: yapi.commons.time() - } - try{ + }; + + try { let result = await groupInst.save(data); + result = yapi.commons.fieldSelect(result, ['_id', 'group_name', 'group_desc', 'uid']); ctx.body = yapi.commons.resReturn(result); - }catch(e){ - ctx.body = yapi.commons.resReturn(null, 402, e.message) + } catch (e) { + ctx.body = yapi.commons.resReturn(null, 402, e.message); } - + } /** @@ -65,14 +71,13 @@ class groupController extends baseController{ * @returns {Object} * @example ./api/group/list.json */ - async list(ctx) { - try{ + try { var groupInst = yapi.getInst(groupModel); let result = await groupInst.list(); - ctx.body = yapi.commons.resReturn(result) - }catch(e){ - ctx.body = yapi.commons.resReturn(null, 402, e.message) + ctx.body = yapi.commons.resReturn(result); + } catch (e) { + ctx.body = yapi.commons.resReturn(null, 402, e.message); } } @@ -86,27 +91,30 @@ class groupController extends baseController{ * @returns {Object} * @example ./api/group/del.json */ + async del(ctx) { + if (this.getRole() !== 'admin') { + return ctx.body = yapi.commons.resReturn(null, 401, '没有权限'); + } - async del(ctx){ - if(this.getRole() !== 'admin'){ - return ctx.body = yapi.commons.resReturn(null,401,'没有权限'); - } - try{ - var groupInst = yapi.getInst(groupModel); - var projectInst = yapi.getInst(projectModel); - let id = ctx.request.body.id; - if(!id){ + try { + let groupInst = yapi.getInst(groupModel); + let projectInst = yapi.getInst(projectModel); + let id = ctx.request.body.id; + + if (!id) { return ctx.body = yapi.commons.resReturn(null, 402, 'id不能为空'); } - let count = await projectInst.countByGroupId(id); - if(count > 0){ + + let count = await projectInst.countByGroupId(id); + + if (count > 0) { return ctx.body = yapi.commons.resReturn(null, 403, '请先删除该分组下的项目'); } let result = await groupInst.del(id); - ctx.body = yapi.commons.resReturn(result) - }catch(err){ - ctx.body = yapi.commons.resReturn(null, 402, e.message) + ctx.body = yapi.commons.resReturn(result); + } catch (err) { + ctx.body = yapi.commons.resReturn(null, 402, err.message); } } @@ -122,33 +130,32 @@ class groupController extends baseController{ * @returns {Object} * @example ./api/group/up.json */ - - async up(ctx){ - if(this.getRole() !== 'admin'){ - return ctx.body = yapi.commons.resReturn(null,401,'没有权限'); + async up(ctx) { + if (this.getRole() !== 'admin') { + return ctx.body = yapi.commons.resReturn(null, 401, '没有权限'); } - try{ - + + try { + ctx.request.body = yapi.commons.handleParams(ctx.request.body, { id: 'number', group_name: 'string', group_desc: 'string' - }) - var groupInst = yapi.getInst(groupModel); + }); + let groupInst = yapi.getInst(groupModel); let id = ctx.request.body.id; let data = {}; - ctx.request.body.group_name && (data.group_name = ctx.request.body.group_name) - ctx.request.body.group_desc && (data.group_desc = ctx.request.body.group_desc) - if(Object.keys(data).length === 0 ){ + ctx.request.body.group_name && (data.group_name = ctx.request.body.group_name); + ctx.request.body.group_desc && (data.group_desc = ctx.request.body.group_desc); + if (Object.keys(data).length === 0) { ctx.body = yapi.commons.resReturn(null, 404, '分组名和分组描述不能为空'); } let result = await groupInst.up(id, data); - ctx.body = yapi.commons.resReturn(result) - }catch(err){ - ctx.body = yapi.commons.resReturn(null, 402, e.message) + ctx.body = yapi.commons.resReturn(result); + } catch (err) { + ctx.body = yapi.commons.resReturn(null, 402, err.message); } } } - -module.exports = groupController +module.exports = groupController; \ No newline at end of file diff --git a/server/utils/commons.js b/server/utils/commons.js index 132442ec..c1a719b1 100644 --- a/server/utils/commons.js +++ b/server/utils/commons.js @@ -115,7 +115,7 @@ exports.sendMail = (options, cb) => { try { yapi.mail.sendMail({ - from: yapi.WEBCONFIG.mail.auth.user, + from: yapi.WEBCONFIG.mail.from, to: options.to, subject: 'yapi平台', html: options.contents diff --git a/server/utils/initConfig.js b/server/utils/initConfig.js index 909a058f..bafb5980 100644 --- a/server/utils/initConfig.js +++ b/server/utils/initConfig.js @@ -2,7 +2,10 @@ import path from 'path'; import fs from 'fs-extra'; import config from '../config.js'; -let configPath = path.join(path.resolve(__dirname, '../../'), 'runtime', 'config.json'); +let runtimePath = config.runtime_path; +fs.ensureDirSync( runtimePath ); +fs.ensureDirSync( path.join(runtimePath, 'log')); +let configPath = path.join(runtimePath, 'config.json') fs.writeFileSync(configPath, JSON.stringify(config, null, '\t'), diff --git a/server/yapi.js b/server/yapi.js index c7d3eb4a..a429e143 100644 --- a/server/yapi.js +++ b/server/yapi.js @@ -1,18 +1,17 @@ import path from 'path'; import fs from 'fs-extra'; import nodemailer from 'nodemailer'; -import config from '../runtime/config.json'; +import config from '../../config.json'; let insts = new Map(); let mail; const WEBROOT = path.resolve(__dirname, '..'); //路径 const WEBROOT_SERVER = __dirname; -const WEBROOT_RUNTIME = path.join(WEBROOT, 'runtime'); +const WEBROOT_RUNTIME = path.resolve(__dirname, '../..'); const WEBROOT_LOG = path.join(WEBROOT_RUNTIME, 'log'); const WEBCONFIG = config; -fs.ensureDirSync(WEBROOT_RUNTIME); fs.ensureDirSync(WEBROOT_LOG); if (WEBCONFIG.mail) { diff --git a/server_dist/config.js b/server_dist/config.js deleted file mode 100644 index bf83b08e..00000000 --- a/server_dist/config.js +++ /dev/null @@ -1,20 +0,0 @@ -'use strict'; - -module.exports = { - 'port': '3000', - 'webhost': 'yapi.local.qunar.com', - 'adminAccount': 'admin@admin.com', - 'db': { - 'servername': '127.0.0.1', - 'DATABASE': 'yapi', - 'port': 27017 - }, - 'mail': { - 'host': 'smtp.mail.com', - 'port': 4652, - 'auth': { - 'user': '****@mail.com', - 'pass': '**********' - } - } -}; \ No newline at end of file diff --git a/server_dist/utils/commons.js b/server_dist/utils/commons.js index b5c1902e..c43f49ee 100644 --- a/server_dist/utils/commons.js +++ b/server_dist/utils/commons.js @@ -141,7 +141,7 @@ exports.sendMail = function (options, cb) { try { _yapi2.default.mail.sendMail({ - from: _yapi2.default.WEBCONFIG.mail.auth.user, + from: _yapi2.default.WEBCONFIG.mail.from, to: options.to, subject: 'yapi平台', html: options.contents diff --git a/server_dist/utils/initConfig.js b/server_dist/utils/initConfig.js index 3fb209b3..c7ae500e 100644 --- a/server_dist/utils/initConfig.js +++ b/server_dist/utils/initConfig.js @@ -18,6 +18,9 @@ var _config2 = _interopRequireDefault(_config); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } -var configPath = _path2.default.join(_path2.default.resolve(__dirname, '../../'), 'runtime', 'config.json'); +var runtimePath = _config2.default.runtime_path; +_fsExtra2.default.ensureDirSync(runtimePath); +_fsExtra2.default.ensureDirSync(_path2.default.join(runtimePath, 'log')); +var configPath = _path2.default.join(runtimePath, 'config.json'); _fsExtra2.default.writeFileSync(configPath, (0, _stringify2.default)(_config2.default, null, '\t'), { encoding: 'utf8' }); \ No newline at end of file diff --git a/server_dist/yapi.js b/server_dist/yapi.js index fe35f0ad..34606718 100644 --- a/server_dist/yapi.js +++ b/server_dist/yapi.js @@ -16,7 +16,7 @@ var _nodemailer = require('nodemailer'); var _nodemailer2 = _interopRequireDefault(_nodemailer); -var _config = require('../runtime/config.json'); +var _config = require('../../config.json'); var _config2 = _interopRequireDefault(_config); @@ -27,11 +27,10 @@ var mail = void 0; var WEBROOT = _path2.default.resolve(__dirname, '..'); //路径 var WEBROOT_SERVER = __dirname; -var WEBROOT_RUNTIME = _path2.default.join(WEBROOT, 'runtime'); +var WEBROOT_RUNTIME = _path2.default.resolve(__dirname, '../..'); var WEBROOT_LOG = _path2.default.join(WEBROOT_RUNTIME, 'log'); var WEBCONFIG = _config2.default; -_fsExtra2.default.ensureDirSync(WEBROOT_RUNTIME); _fsExtra2.default.ensureDirSync(WEBROOT_LOG); if (WEBCONFIG.mail) { diff --git a/service.sh b/service.sh new file mode 100644 index 00000000..f9d4b434 --- /dev/null +++ b/service.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +prog="/var/soft/node-v6.11.1-linux-x64/bin/pm2" +app="/home/q/www/yapi.beta.corp.qunar.com/webapp/server_dist/app.js" + + + +start() { + echo "Starting Server..." + eval "$prog start $app --name=yapi" +} + +stop() { + echo "Stopping Server..." + eval "$prog stop yapi" +} + +restart() { + echo "Restart Server..." + eval "$prog restart yapi" +} + + + + +case "$1" in +start) +start && exit 0 +;; +stop) +stop || exit 0 +;; +restart) +restart || exit 0 +;; +*) +echo $"Usage: $0 {start|stop|restart}" +exit 2 +esac \ No newline at end of file