add proxy

1:增加开发模式的代理服务器
2:删除 MOCK_URL 配置
This commit is contained in:
sc 2021-07-15 14:11:21 +08:00
parent 77bc119c35
commit 5b78760ccb
4 changed files with 32 additions and 25 deletions

View File

@ -6,6 +6,6 @@ const APP_CONFIG = {
//标题
APP_NAME: "SCUI",
//接口地址
API_URL: ""
//接口地址如遇跨域需使用nginx代理
API_URL: "https://www.fastmock.site/mock/44c807475f7eeba73409792255781935/api"
}

View File

@ -12,7 +12,7 @@ import http from "@/utils/request";
const api = {
default: {
upload: {
url: `${config.MOCK_URL}/upload`,
url: `${config.API_URL}/upload`,
name: "文件上传",
post: async function(data){
return await http.post(this.url, data);
@ -21,51 +21,51 @@ const api = {
},
user: {
login: {
url: `${config.MOCK_URL}/login`,
url: `${config.API_URL}/login`,
name: "登录获取用户菜单和权限,全部权限",
get: async function(){
return await http.get(this.url);
}
},
login_demo: {
url: `${config.MOCK_URL}/login_user`,
url: `${config.API_URL}/login_user`,
name: "登录获取用户菜单和权限,部分权限",
get: async function(){
return await http.get(this.url);
}
},
list: {
url: `${config.MOCK_URL}/user_list`,
url: `${config.API_URL}/user_list`,
name: "获取用户列表",
get: async function(params={}){
return await http.get(this.url, params);
}
},
save: {
url: `${config.MOCK_URL}/post`,
url: `${config.API_URL}/post`,
name: "新增编辑用户",
post: async function(params={}){
return await http.get(this.url, params);
return await http.post(this.url, params);
}
},
del: {
url: `${config.MOCK_URL}/post`,
url: `${config.API_URL}/post`,
name: "删除用户",
post: async function(params={}){
return await http.get(this.url, params);
return await http.post(this.url, params);
}
}
},
role: {
select: {
url: `${config.MOCK_URL}/role`,
url: `${config.API_URL}/role`,
name: "角色选择列表",
get: async function(){
return await http.get(this.url);
}
},
list: {
url: `${config.MOCK_URL}/role`,
url: `${config.API_URL}/role`,
name: "角色列表",
get: async function(){
return await http.get(this.url);
@ -74,14 +74,14 @@ const api = {
},
dic: {
list: {
url: `${config.MOCK_URL}/dic_list`,
url: `${config.API_URL}/dic_list`,
name: "字典列表",
get: async function(){
return await http.get(this.url);
}
},
info: {
url: `${config.MOCK_URL}/dic_info`,
url: `${config.API_URL}/dic_info`,
name: "字典明细",
get: async function(params){
return await http.get(this.url, params);
@ -90,7 +90,7 @@ const api = {
},
app: {
list: {
url: `${config.MOCK_URL}/app`,
url: `${config.API_URL}/app`,
name: "应用列表",
get: async function(){
return await http.get(this.url);
@ -99,7 +99,7 @@ const api = {
},
menu: {
list: {
url: `${config.MOCK_URL}/login`,
url: `${config.API_URL}/login`,
name: "菜单管理",
get: async function(){
// 这里接口对象偷懒重复了登录接口
@ -111,7 +111,7 @@ const api = {
},
log: {
list: {
url: `${config.MOCK_URL}/loglist`,
url: `${config.API_URL}/loglist`,
name: "日志列表",
get: async function(params){
return await http.get(this.url, params);
@ -120,14 +120,14 @@ const api = {
},
demo: {
page: {
url: `${config.MOCK_URL}/page`,
url: `${config.API_URL}/page`,
name: "分页列表",
get: async function(params){
return await http.get(this.url, params);
}
},
upload: {
url: `${config.MOCK_URL}/upload`,
url: `${config.API_URL}/upload`,
name: "文件上传接口",
post: async function(data){
return await http.post(this.url, data);

View File

@ -6,10 +6,7 @@ const DEFAULT_CONFIG = {
APP_VER: "1.1.16",
//接口地址
API_URL: "",
//MOCK接口地址
MOCK_URL: "https://www.fastmock.site/mock/44c807475f7eeba73409792255781935/api",
API_URL: "/api",
//TokenName
TOKEN_NAME: "Authorization",

View File

@ -7,9 +7,19 @@ module.exports = {
// build编译后不生成资源MAP文件
productionSourceMap: false,
//开发服务,build后的生产模式还需nginx代理
devServer: {
open: false, //运行后自动打开游览器
port: 2800 //挂载端口
port: 2800, //挂载端口
proxy: {
'/api': {
target: 'https://www.fastmock.site/mock/44c807475f7eeba73409792255781935/api',
ws: true,
pathRewrite: {
'^/api': '/'
}
}
}
},
chainWebpack: config => {