Skip to content

Commit

Permalink
fix(system-client): fix app api url access;
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow committed Sep 4, 2021
1 parent 36e398c commit 348ca7e
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 50 deletions.
7 changes: 5 additions & 2 deletions packages/system-client/.env.development
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# just a flag
ENV = 'development'

# base api
VUE_APP_BASE_API = '/dev-api'
# sys api base url
VUE_APP_BASE_API_SYS = '/sys-api'

# app api base url
VUE_APP_BASE_API_APP = '/app-api'
8 changes: 4 additions & 4 deletions packages/system-client/.env.production
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# just a flag
ENV = 'production'

# base api
VUE_APP_BASE_API = '/prod-api'
# sys api base url
VUE_APP_BASE_API_SYS = '/sys-api'

# app server 请求地址
VUE_APP_BASE_API_APP = '/prod-api/app'
# app api base url
VUE_APP_BASE_API_APP = '/app-api'
8 changes: 4 additions & 4 deletions packages/system-client/.env.staging
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ NODE_ENV = production
# just a flag
ENV = 'staging'

# base api
VUE_APP_BASE_API = '/stage-api'
# sys api base url
VUE_APP_BASE_API_SYS = '/sys-api'

# app server 请求地址
VUE_APP_BASE_API_APP = '/stage-api/app'
# app api base url
VUE_APP_BASE_API_APP = '/app-api'
2 changes: 1 addition & 1 deletion packages/system-client/src/api/cloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CloudRequest extends Request {
}

export const cloud = new Cloud({
baseUrl: process.env.VUE_APP_BASE_API,
baseUrl: process.env.VUE_APP_BASE_API_SYS,
entryUrl: '/admin/entry',
getAccessToken: getToken,
requestClass: CloudRequest
Expand Down
2 changes: 1 addition & 1 deletion packages/system-client/src/api/collec.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function deleCollectionIndex(collection, index) {
export function getDb() {
const appid = store.state.app.appid
const dbm_cloud = new Cloud({
baseUrl: process.env.VUE_APP_BASE_API,
baseUrl: process.env.VUE_APP_BASE_API_SYS,
entryUrl: `/apps/${appid}/dbm/entry`,
getAccessToken: getToken
})
Expand Down
18 changes: 12 additions & 6 deletions packages/system-client/src/api/func.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import store from '@/store'
import request from '@/utils/request'
import axios from 'axios'

/**
* Get cloud function list
Expand Down Expand Up @@ -91,26 +92,31 @@ export function publishFunctions() {
/**
* Debug cloud function
*/
export function launchFunction(functionName, data, debug = false) {
export async function launchFunction(functionName, data, debug = false) {
const appid = store.state.app.appid
return request({
url: `/apps/${appid}/function/debug/${functionName}`,
const res = await axios({
url: `/app-api/${appid}/func/invoke/${functionName}`,
method: 'post',
data: data,
headers: {
'debug-token': debug
}
})

return res.data
}

/**
* 加载依赖包的类型声明文件
* @param {string} packageName
* @returns
*/
export function loadPackageTypings(packageName) {
return request({
url: `/app/typing/package?packageName=${packageName}`,
export async function loadPackageTypings(packageName) {
const appid = store.state.app.appid
const res = await axios({
url: `/app-api/${appid}/typing/package?packageName=${packageName}`,
method: 'GET'
})

return res.data
}
2 changes: 2 additions & 0 deletions packages/system-client/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ import './utils/error-log' // error log

import * as filters from './filters' // global filters
import clipboard from '@/directive/clipboard/index'
import permission from '@/directive/permission'

Vue.use(clipboard)
Vue.use(permission)

Vue.use(Element, {
size: Cookies.get('size') || 'medium' // set element-ui default size
Expand Down
2 changes: 1 addition & 1 deletion packages/system-client/src/utils/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getToken } from '@/utils/auth'

// create an axios instance
const service = axios.create({
baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
baseURL: process.env.VUE_APP_BASE_API_SYS, // url = base url + request url
// withCredentials: true, // send cookies when cross-domain requests
timeout: 60000 // request timeout
})
Expand Down
46 changes: 21 additions & 25 deletions packages/system-client/src/views/development/function.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<span style="font-size: 26px;line-height: 40px;"><b>{{ func.label }}</b> </span>
<el-tag v-clipboard:message="func.name" v-clipboard:success="onCopy" style="margin-left: 20px; " size="small" type="success">{{ func.name }}</el-tag>
<el-button
v-permission="'function.read'"
style="margin-left: 20px"
icon="el-icon-refresh"
type="text"
Expand All @@ -13,7 +12,6 @@
@click="getFunction"
>刷新</el-button>
<el-button
v-permission="'function.edit'"
type="success"
size="small"
style="margin-left: 20px;"
Expand Down Expand Up @@ -60,7 +58,6 @@
<div class="title">
调用参数
<el-button
v-permission="'function.debug'"
size="mini"
type="success"
style="margin-left: 10px"
Expand Down Expand Up @@ -109,7 +106,7 @@
import FunctionLogDetail from './components/FunctionLogDetail'
import FunctionEditor from '@/components/FunctionEditor'
import jsonEditor from '@/components/JsonEditor/param'
import { db, dbm_cloud } from '../../api/cloud'
import { db } from '../../api/cloud'
import { getFunctionById, launchFunction } from '../../api/func'
import { publishFunctions } from '../../api/func'
import { getDebugToken } from '../../utils/auth'
Expand Down Expand Up @@ -262,7 +259,7 @@ export default {
*/
async launch() {
const debug_token = getDebugToken()
await this.updateFunc(false)
// await this.updateFunc(false)
if (this.loading) {
return
}
Expand All @@ -286,30 +283,30 @@ export default {
* 获取最近日志
*/
async getLatestLogs() {
this.loading = true
const db = dbm_cloud.database()
// 执行数据查询
const res = await db.collection('__function_logs')
.where({ func_id: this.func_id })
.limit(20)
.skip(0)
.orderBy('created_at', 'desc')
.get()
.finally(() => { this.loading = false })
this.lastestLogs = res.data || []
// this.loading = true
// const db = dbm_cloud.database()
// // 执行数据查询
// const res = await db.collection('__function_logs')
// .where({ func_id: this.func_id })
// .limit(20)
// .skip(0)
// .orderBy('created_at', 'desc')
// .get()
// .finally(() => { this.loading = false })
// this.lastestLogs = res.data || []
},
/**
* 添加函数的更新记录
*/
async addFunctionHistory() {
const data = Object.assign({}, this.func)
await db.collection(Constants.cn.function_history)
.add({
func_id: this.func._id,
data: data,
created_at: Date.now()
})
// const data = Object.assign({}, this.func)
// await db.collection(Constants.cn.function_history)
// .add({
// func_id: this.func._id,
// data: data,
// created_at: Date.now()
// })
},
showLogDetailDlg(log) {
this.logDetail = log
Expand Down Expand Up @@ -340,7 +337,6 @@ export default {
try {
param = JSON.parse(data)
} catch (error) {
console.log(data, error)
param = data
}
Expand Down
19 changes: 13 additions & 6 deletions packages/system-client/vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,19 @@ module.exports = {
// before: require('./mock/mock-server.js'),
proxy: {
// detail: https://cli.vuejs.org/config/#devserver-proxy
[process.env.VUE_APP_BASE_API]: {
target: 'http://localhost:9000/',
changeOrigin: true,
pathRewrite: {
['^' + process.env.VUE_APP_BASE_API]: ''
}
[process.env.VUE_APP_BASE_API_SYS]: {
target: 'http://localhost:8080/',
changeOrigin: true
// pathRewrite: {
// ['^' + process.env.VUE_APP_BASE_API_SYS]: ''
// }
},
[process.env.VUE_APP_BASE_API_APP]: {
target: 'http://localhost:8080/',
changeOrigin: true
// pathRewrite: {
// ['^' + process.env.VUE_APP_BASE_API_APP]: ''
// }
}
},
disableHostCheck: true
Expand Down

0 comments on commit 348ca7e

Please sign in to comment.