mirror of
https://github.com/YMFE/yapi.git
synced 2024-11-27 04:40:08 +08:00
feat: 优化url,去掉#,后端接口统一使用/api前缀
This commit is contained in:
parent
87220f2182
commit
fcc35d924a
@ -1,7 +1,7 @@
|
||||
import React, { Component } from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Route, HashRouter, Redirect, Switch } from 'react-router-dom';
|
||||
import { Route, BrowserRouter as Router, Redirect, Switch } from 'react-router-dom';
|
||||
import { Home, Group, Project, News, AddInterface, Follows, AddProject } from './containers/index';
|
||||
import User from './containers/User/User.js';
|
||||
import Header from './components/Header/Header';
|
||||
@ -45,7 +45,7 @@ export default class App extends Component {
|
||||
return <Loading visible />;
|
||||
} else {
|
||||
r = (
|
||||
<HashRouter>
|
||||
<Router>
|
||||
<div className="router-main">
|
||||
<Header />
|
||||
<div className="router-container">
|
||||
@ -63,7 +63,7 @@ export default class App extends Component {
|
||||
</div>
|
||||
<Footer />
|
||||
</div>
|
||||
</HashRouter>
|
||||
</Router>
|
||||
)
|
||||
}
|
||||
return r;
|
||||
|
@ -31,7 +31,7 @@ export default class BreadcrumbNavigation extends Component {
|
||||
type = 'project';
|
||||
}
|
||||
const params = { type, id };
|
||||
axios.get('/user/nav', {params: params}).then( (res) => {
|
||||
axios.get('/api/user/nav', {params: params}).then( (res) => {
|
||||
const data = res.data.data;
|
||||
// 依次填入group/projec/interface
|
||||
if (data.group_name) {
|
||||
|
@ -69,7 +69,7 @@ const ToolUser = (props)=> (
|
||||
/>
|
||||
}>
|
||||
<a className="dropdown-link">
|
||||
<img style={{width:24,height:24}} src="/user/avatar" /><span className="name">{props.user}</span>
|
||||
<img style={{width:30,height:30}} src="/api/user/avatar" /><span className="name">{props.user}</span>
|
||||
</a>
|
||||
</Dropdown>
|
||||
</li>
|
||||
|
@ -49,7 +49,7 @@ export default class Srch extends Component{
|
||||
}
|
||||
|
||||
handleSearch = (value) => {
|
||||
axios.get('/project/search?q='+value)
|
||||
axios.get('/api/project/search?q='+value)
|
||||
.then((res) => {
|
||||
if(res.data && res.data.errcode === 0){
|
||||
const dataSource = [];
|
||||
|
@ -147,7 +147,7 @@ class AddInterface extends Component {
|
||||
|
||||
getMockURL (project_id, result) {
|
||||
const params = {id: project_id}
|
||||
axios.get('/project/get', {params: params}).
|
||||
axios.get('/api/project/get', {params: params}).
|
||||
then( data => {
|
||||
const { prd_host, basepath } = data.data.data
|
||||
const mockURL = `http://${prd_host}${basepath}${result.path}`
|
||||
|
@ -106,7 +106,7 @@ export default class GroupList extends Component {
|
||||
@autobind
|
||||
async addGroup() {
|
||||
const { newGroupName: group_name, newGroupDesc: group_desc } = this.state;
|
||||
const res = await axios.post('/group/add', { group_name, group_desc })
|
||||
const res = await axios.post('/api/group/add', { group_name, group_desc })
|
||||
if (!res.data.errcode) {
|
||||
this.setState({
|
||||
addGroupModalVisible: false
|
||||
@ -120,7 +120,7 @@ export default class GroupList extends Component {
|
||||
async editGroup() {
|
||||
const { currGroupName: group_name, currGroupDesc: group_desc } = this.state;
|
||||
const id = this.props.currGroup._id;
|
||||
const res = axios.post('/group/up', { group_name, group_desc, id });
|
||||
const res = axios.post('/api/group/up', { group_name, group_desc, id });
|
||||
if (res.data.errcode) {
|
||||
message.error(res.data.errmsg);
|
||||
} else {
|
||||
@ -159,7 +159,7 @@ export default class GroupList extends Component {
|
||||
async deleteGroup() {
|
||||
const self = this;
|
||||
const { currGroup } = self.props;
|
||||
const res = await axios.post('/group/del', {id: currGroup._id})
|
||||
const res = await axios.post('/api/group/del', {id: currGroup._id})
|
||||
if (res.data.errcode) {
|
||||
message.error(res.data.errmsg);
|
||||
} else {
|
||||
|
@ -31,7 +31,7 @@ class InterfaceMode extends Component {
|
||||
const params = {
|
||||
id: this.getInterfaceId()
|
||||
}
|
||||
axios.get('/project/get_member_list', { params })
|
||||
axios.get('/api/project/get_member_list', { params })
|
||||
.then(data => {
|
||||
this.setState({
|
||||
'memberList': data.data.data
|
||||
@ -57,7 +57,7 @@ class InterfaceMode extends Component {
|
||||
id: this.getInterfaceId()
|
||||
}
|
||||
|
||||
axios.post('/project/del_member', params)
|
||||
axios.post('/api/project/del_member', params)
|
||||
.then(() => {
|
||||
this.getMemberList()
|
||||
})
|
||||
@ -70,11 +70,11 @@ class InterfaceMode extends Component {
|
||||
addNewUser () {
|
||||
const { userName } = this.state
|
||||
const params = { q: userName}
|
||||
axios.get('/user/search', { params })
|
||||
axios.get('/api/user/search', { params })
|
||||
.then(data => {
|
||||
const member_uid = data.data.data[0].uid
|
||||
const params = {id: this.getInterfaceId(), member_uid}
|
||||
axios.post('/project/add_member', params)
|
||||
axios.post('/api/project/add_member', params)
|
||||
.then( () => {
|
||||
this.getMemberList()
|
||||
})
|
||||
@ -94,7 +94,7 @@ class InterfaceMode extends Component {
|
||||
})
|
||||
const params = { q: value}
|
||||
|
||||
axios.get('/user/search', { params })
|
||||
axios.get('/api/user/search', { params })
|
||||
.then(data => {
|
||||
const userList = []
|
||||
data = data.data.data
|
||||
|
@ -51,7 +51,7 @@ class InterfaceTable extends Component {
|
||||
const params = {
|
||||
id: interfaceId
|
||||
}
|
||||
axios.post('/interface/del', params)
|
||||
axios.post('/api/interface/del', params)
|
||||
.then(() => {
|
||||
this.deleteInterfaceData(interfaceId)
|
||||
})
|
||||
|
@ -42,7 +42,7 @@ class LeftMenu extends Component {
|
||||
this.interval = setInterval(() => {
|
||||
if (this.searchSign === this._searchSign) {
|
||||
this.interval = clearInterval(this.interval)
|
||||
axios.get('/user/search?q=' + value).then((res) => {
|
||||
axios.get('/api/user/search?q=' + value).then((res) => {
|
||||
if (res.data.errcode === 0) {
|
||||
this.setState({
|
||||
dataSource: res.data.data
|
||||
|
@ -39,7 +39,7 @@ class List extends Component {
|
||||
}
|
||||
|
||||
getUserList() {
|
||||
axios.get('/user/list?page=' + this.state.current).then((res) => {
|
||||
axios.get('/api/user/list?page=' + this.state.current).then((res) => {
|
||||
let result = res.data;
|
||||
|
||||
if (result.errcode === 0) {
|
||||
@ -62,7 +62,7 @@ class List extends Component {
|
||||
}
|
||||
|
||||
confirm = (uid) =>{
|
||||
axios.post('/user/del', {
|
||||
axios.post('/api/user/del', {
|
||||
id: uid
|
||||
}).then( (res)=>{
|
||||
if(res.data.errcode === 0){
|
||||
|
@ -38,7 +38,7 @@ class Profile extends Component {
|
||||
|
||||
getUserInfo = (id) => {
|
||||
var _this = this;
|
||||
axios.get('/user/find?id=' + id).then((res) => {
|
||||
axios.get('/api/user/find?id=' + id).then((res) => {
|
||||
_this.setState({
|
||||
userinfo: res.data.data,
|
||||
_userinfo: res.data.data
|
||||
@ -52,7 +52,7 @@ class Profile extends Component {
|
||||
let params = {uid: state.userinfo.uid}
|
||||
params[name] = value;
|
||||
|
||||
axios.post('/user/update', params).then( (res)=>{
|
||||
axios.post('/api/user/update', params).then( (res)=>{
|
||||
let data = res.data;
|
||||
if(data.errcode === 0){
|
||||
let userinfo = this.state.userinfo;
|
||||
@ -106,7 +106,7 @@ class Profile extends Component {
|
||||
}
|
||||
|
||||
|
||||
axios.post('/user/change_password', params).then( (res)=>{
|
||||
axios.post('/api/user/change_password', params).then( (res)=>{
|
||||
let data = res.data;
|
||||
if(data.errcode === 0){
|
||||
this.handleEdit('secureEdit', false)
|
||||
|
@ -161,7 +161,7 @@ export function pushInterfaceMethod (value) {
|
||||
export function fetchInterfaceProject(id) {
|
||||
return {
|
||||
type: FETCH_INTERFACE_PROJECT,
|
||||
payload: axios.get('/project/get', { params: {id}})
|
||||
payload: axios.get('/api/project/get', { params: {id}})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ export default (state = initialState, action) => {
|
||||
export function fetchGroupList() {
|
||||
return {
|
||||
type: FETCH_GROUP_LIST,
|
||||
payload: axios.get('/group/list')
|
||||
payload: axios.get('/api/group/list')
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ export default (state = initialState, action) => {
|
||||
// Action Creators
|
||||
export function checkLoginState() {
|
||||
return(dispatch)=> {
|
||||
axios.get('/user/status').then((res) => {
|
||||
axios.get('/api/user/status').then((res) => {
|
||||
dispatch({
|
||||
type: GET_LOGIN_STATE,
|
||||
payload: res
|
||||
@ -94,7 +94,7 @@ export function checkLoginState() {
|
||||
export function loginActions(data) {
|
||||
return {
|
||||
type: LOGIN,
|
||||
payload: axios.post('/user/login', data)
|
||||
payload: axios.post('/api/user/login', data)
|
||||
};
|
||||
}
|
||||
|
||||
@ -107,14 +107,14 @@ export function regActions(data) {
|
||||
};
|
||||
return {
|
||||
type: REGISTER,
|
||||
payload: axios.post('/user/reg', param)
|
||||
payload: axios.post('/api/user/reg', param)
|
||||
};
|
||||
}
|
||||
|
||||
export function logoutActions() {
|
||||
return {
|
||||
type: LOGIN_OUT,
|
||||
payload: axios.get('./user/logout')
|
||||
payload: axios.get('/api/user/logout')
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ export function fetchNewsData (typeid,page,limit) {
|
||||
}
|
||||
return {
|
||||
type: FETCH_NEWS_DATA,
|
||||
payload: axios.get('/log/list',{
|
||||
payload: axios.get('/api/log/list',{
|
||||
params: param
|
||||
})
|
||||
};
|
||||
@ -56,7 +56,7 @@ export function getMockUrl(project_id){
|
||||
const params = {id: project_id};
|
||||
return {
|
||||
type:"",
|
||||
payload: axios.get('/project/get', {params: params})
|
||||
payload: axios.get('/api/project/get', {params: params})
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ export default (state = initialState, action) => {
|
||||
export function fetchProjectList(id, pageNum) {
|
||||
return {
|
||||
type: FETCH_PROJECT_LIST,
|
||||
payload: axios.get('/project/list', {
|
||||
payload: axios.get('/api/project/list', {
|
||||
params: {
|
||||
group_id: id,
|
||||
page: pageNum || 1,
|
||||
@ -95,7 +95,7 @@ export function addProject(data) {
|
||||
};
|
||||
return {
|
||||
type: PROJECT_ADD,
|
||||
payload: axios.post('/project/add', param)
|
||||
payload: axios.post('/api/project/add', param)
|
||||
};
|
||||
}
|
||||
|
||||
@ -112,7 +112,7 @@ export function updateProject(data) {
|
||||
};
|
||||
return {
|
||||
type: PROJECT_UPDATE,
|
||||
payload: axios.post('/project/up', param)
|
||||
payload: axios.post('/api/project/up', param)
|
||||
};
|
||||
}
|
||||
|
||||
@ -120,6 +120,6 @@ export function delProject(id) {
|
||||
const param = { id };
|
||||
return {
|
||||
type: PROJECT_DEL,
|
||||
payload: axios.post('/project/del', param)
|
||||
payload: axios.post('/api/project/del', param)
|
||||
};
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ gulp.task('initialBuild', ['removeDist'], () => {
|
||||
output('success', '初始编译成功!');
|
||||
waitingSpinner();
|
||||
|
||||
excuteCmd('node_modules/.bin/nodemon', ['-q', 'server_dist/app.js'], {
|
||||
excuteCmd('node_modules/.bin/nodemon', ['-q', 'server_dist/app.js', 'dev'], {
|
||||
cwd: __dirname
|
||||
});
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build-server": "babel server -d server_dist",
|
||||
"dev-server": "nodemon server_dist/app.js -L",
|
||||
"dev-server": "nodemon server_dist/app.js dev -L",
|
||||
"install-server": "node server_dist/install.js",
|
||||
"dev": "gulp --silent",
|
||||
"build": "gulp build --silent",
|
||||
|
@ -10,13 +10,29 @@ import router from './router.js';
|
||||
|
||||
yapi.connect = dbModule.connect();
|
||||
const app = new Koa();
|
||||
let indexFile = process.argv[2] === 'dev' ? 'dev.html' : 'index.html';
|
||||
|
||||
|
||||
app.use(mockServer);
|
||||
app.use(bodyParser());
|
||||
app.use(router.routes());
|
||||
app.use(router.allowedMethods());
|
||||
|
||||
|
||||
|
||||
app.use( async (ctx, next) => {
|
||||
if( /^\/(?!api)[a-zA-Z0-9\/\-]*$/.test(ctx.path) ){
|
||||
ctx.path = "/"
|
||||
await next()
|
||||
}else{
|
||||
await next()
|
||||
}
|
||||
|
||||
})
|
||||
app.use(koaStatic(
|
||||
yapi.path.join(yapi.WEBROOT, 'static')
|
||||
yapi.path.join(yapi.WEBROOT, 'static'),
|
||||
{index: indexFile}
|
||||
));
|
||||
|
||||
app.listen(yapi.WEBCONFIG.port);
|
||||
commons.log(`the server is start at port ${yapi.WEBCONFIG.port}`);
|
@ -451,7 +451,9 @@ class userController extends baseController {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 上传用户头像
|
||||
* @interface /user/upload_avatar
|
||||
* @method POST
|
||||
* @param {*} basecode base64编码,通过h5 api传给后端
|
||||
*/
|
||||
|
||||
|
@ -312,7 +312,7 @@ for(let ctrl in routerConfig){
|
||||
* @param {*} action controller_action_name
|
||||
*/
|
||||
function createAction(controller, action, path, method) {
|
||||
router[method](INTERFACE_CONFIG[controller].prefix + path, async (ctx) => {
|
||||
router[method]("/api" + INTERFACE_CONFIG[controller].prefix + path, async (ctx) => {
|
||||
let inst = new INTERFACE_CONFIG[controller].controller(ctx);
|
||||
|
||||
await inst.init(ctx);
|
||||
@ -325,4 +325,5 @@ function createAction(controller, action, path, method) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
module.exports = router;
|
||||
|
@ -1,5 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
var _regenerator = require('babel-runtime/regenerator');
|
||||
|
||||
var _regenerator2 = _interopRequireDefault(_regenerator);
|
||||
|
||||
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
|
||||
|
||||
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
|
||||
|
||||
var _yapi = require('./yapi.js');
|
||||
|
||||
var _yapi2 = _interopRequireDefault(_yapi);
|
||||
@ -39,11 +47,49 @@ _yapi2.default.commons = _commons2.default;
|
||||
|
||||
_yapi2.default.connect = _db2.default.connect();
|
||||
var app = new _koa2.default();
|
||||
var indexFile = process.argv[2] === 'dev' ? 'dev.html' : 'index.html';
|
||||
|
||||
app.use(_mockServer2.default);
|
||||
app.use((0, _koaBodyparser2.default)());
|
||||
app.use(_router2.default.routes());
|
||||
app.use(_router2.default.allowedMethods());
|
||||
app.use((0, _koaStatic2.default)(_yapi2.default.path.join(_yapi2.default.WEBROOT, 'static')));
|
||||
|
||||
app.use(function () {
|
||||
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(ctx, next) {
|
||||
return _regenerator2.default.wrap(function _callee$(_context) {
|
||||
while (1) {
|
||||
switch (_context.prev = _context.next) {
|
||||
case 0:
|
||||
if (!/^\/(?!api)[a-zA-Z0-9\/\-]*$/.test(ctx.path)) {
|
||||
_context.next = 6;
|
||||
break;
|
||||
}
|
||||
|
||||
ctx.path = "/";
|
||||
_context.next = 4;
|
||||
return next();
|
||||
|
||||
case 4:
|
||||
_context.next = 8;
|
||||
break;
|
||||
|
||||
case 6:
|
||||
_context.next = 8;
|
||||
return next();
|
||||
|
||||
case 8:
|
||||
case 'end':
|
||||
return _context.stop();
|
||||
}
|
||||
}
|
||||
}, _callee, undefined);
|
||||
}));
|
||||
|
||||
return function (_x, _x2) {
|
||||
return _ref.apply(this, arguments);
|
||||
};
|
||||
}());
|
||||
app.use((0, _koaStatic2.default)(_yapi2.default.path.join(_yapi2.default.WEBROOT, 'static'), { index: indexFile }));
|
||||
|
||||
app.listen(_yapi2.default.WEBCONFIG.port);
|
||||
_commons2.default.log('the server is start at port ' + _yapi2.default.WEBCONFIG.port);
|
@ -938,7 +938,9 @@ var userController = function (_baseController) {
|
||||
}()
|
||||
|
||||
/**
|
||||
*
|
||||
* 上传用户头像
|
||||
* @interface /user/upload_avatar
|
||||
* @method POST
|
||||
* @param {*} basecode base64编码,通过h5 api传给后端
|
||||
*/
|
||||
|
||||
|
@ -1,36 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var _regenerator = require("babel-runtime/regenerator");
|
||||
|
||||
var _regenerator2 = _interopRequireDefault(_regenerator);
|
||||
|
||||
var _asyncToGenerator2 = require("babel-runtime/helpers/asyncToGenerator");
|
||||
|
||||
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// const jwt = require('jsonwebtoken');
|
||||
//检查token是否过期
|
||||
|
||||
module.exports = function () {
|
||||
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(ctx, next) {
|
||||
return _regenerator2.default.wrap(function _callee$(_context) {
|
||||
while (1) {
|
||||
switch (_context.prev = _context.next) {
|
||||
case 0:
|
||||
_context.next = 2;
|
||||
return next();
|
||||
|
||||
case 2:
|
||||
case "end":
|
||||
return _context.stop();
|
||||
}
|
||||
}
|
||||
}, _callee, undefined);
|
||||
}));
|
||||
|
||||
return function (_x, _x2) {
|
||||
return _ref.apply(this, arguments);
|
||||
};
|
||||
}();
|
@ -1,44 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var _regenerator = require("babel-runtime/regenerator");
|
||||
|
||||
var _regenerator2 = _interopRequireDefault(_regenerator);
|
||||
|
||||
var _asyncToGenerator2 = require("babel-runtime/helpers/asyncToGenerator");
|
||||
|
||||
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
module.exports = function () {
|
||||
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(ctx, next) {
|
||||
var path;
|
||||
return _regenerator2.default.wrap(function _callee$(_context) {
|
||||
while (1) {
|
||||
switch (_context.prev = _context.next) {
|
||||
case 0:
|
||||
path = ctx.path;
|
||||
|
||||
console.log(path); // eslint-disable-line
|
||||
console.log(ctx.hostname); // eslint-disable-line
|
||||
|
||||
if (!next) {
|
||||
_context.next = 6;
|
||||
break;
|
||||
}
|
||||
|
||||
_context.next = 6;
|
||||
return next();
|
||||
|
||||
case 6:
|
||||
case "end":
|
||||
return _context.stop();
|
||||
}
|
||||
}
|
||||
}, _callee, undefined);
|
||||
}));
|
||||
|
||||
return function (_x, _x2) {
|
||||
return _ref.apply(this, arguments);
|
||||
};
|
||||
}();
|
@ -314,7 +314,7 @@ for (var ctrl in routerConfig) {
|
||||
function createAction(controller, action, path, method) {
|
||||
var _this = this;
|
||||
|
||||
router[method](INTERFACE_CONFIG[controller].prefix + path, function () {
|
||||
router[method]("/api" + INTERFACE_CONFIG[controller].prefix + path, function () {
|
||||
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(ctx) {
|
||||
var inst;
|
||||
return _regenerator2.default.wrap(function _callee$(_context) {
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 25 KiB |
@ -6,7 +6,6 @@
|
||||
<title>YAPI-高效、易用、功能强大的api管理平台</title>
|
||||
<script>
|
||||
document.write('<script src="prd/assets.js?v=' + Math.random() + '"><\/script>');
|
||||
console.log(window)
|
||||
</script>
|
||||
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user