fix: fixed mock server (#541)

This commit is contained in:
花裤衩 2020-01-09 20:53:06 +08:00 committed by GitHub
parent 227ca9b649
commit 95c7bf5d10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 11 additions and 21 deletions

View File

@ -53,9 +53,10 @@ export function mockXHR() {
// for mock server
const responseFake = (url, type, respond) => {
return {
url: new RegExp(`/mock${url}`),
url: new RegExp(`${process.env.VUE_APP_BASE_API}${url}`),
type: type || 'get',
response(req, res) {
console.log('request invoke:' + req.path)
res.json(Mock.mock(respond instanceof Function ? respond(req, res) : respond))
}
}

View File

@ -13,7 +13,7 @@ const data = Mock.mock({
export default [
{
url: '/table/list',
url: '/vue-admin-template/table/list',
type: 'get',
response: config => {
const items = data.items

View File

@ -26,7 +26,7 @@ const users = {
export default [
// user login
{
url: '/user/login',
url: '/vue-admin-template/user/login',
type: 'post',
response: config => {
const { username } = config.body
@ -49,7 +49,7 @@ export default [
// get user info
{
url: '/user/info\.*',
url: '/vue-admin-template/user/info\.*',
type: 'get',
response: config => {
const { token } = config.query
@ -72,7 +72,7 @@ export default [
// user logout
{
url: '/user/logout',
url: '/vue-admin-template/user/logout',
type: 'post',
response: _ => {
return {

View File

@ -2,7 +2,7 @@ import request from '@/utils/request'
export function getList(params) {
return request({
url: '/table/list',
url: '/vue-admin-template/table/list',
method: 'get',
params
})

View File

@ -2,7 +2,7 @@ import request from '@/utils/request'
export function login(data) {
return request({
url: '/user/login',
url: '/vue-admin-template/user/login',
method: 'post',
data
})
@ -10,7 +10,7 @@ export function login(data) {
export function getInfo(token) {
return request({
url: '/user/info',
url: '/vue-admin-template/user/info',
method: 'get',
params: { token }
})
@ -18,7 +18,7 @@ export function getInfo(token) {
export function logout() {
return request({
url: '/user/logout',
url: '/vue-admin-template/user/logout',
method: 'post'
})
}

View File

@ -36,18 +36,7 @@ module.exports = {
warnings: false,
errors: true
},
proxy: {
// change xxx-api/login => mock/login
// detail: https://cli.vuejs.org/config/#devserver-proxy
[process.env.VUE_APP_BASE_API]: {
target: `http://127.0.0.1:${port}/mock`,
changeOrigin: true,
pathRewrite: {
['^' + process.env.VUE_APP_BASE_API]: ''
}
}
},
after: require('./mock/mock-server.js')
before: require('./mock/mock-server.js')
},
configureWebpack: {
// provide the app's title in webpack's name field, so that