diff --git a/packages/app-service/src/router/function/debug.ts b/packages/app-service/src/router/function/debug.ts index 7df72e2940..1df8b6b301 100644 --- a/packages/app-service/src/router/function/debug.ts +++ b/packages/app-service/src/router/function/debug.ts @@ -1,13 +1,12 @@ /* * @Author: Maslow * @Date: 2021-07-30 10:30:29 - * @LastEditTime: 2021-10-06 21:37:48 + * @LastEditTime: 2021-11-01 18:55:44 * @Description: */ import { Request, Response } from 'express' import { FunctionContext, CloudFunction } from 'cloud-function-engine' -import { getFunctionByName } from '../../api/function' import { parseToken } from '../../lib/utils/token' import { logger } from '../../lib/logger' import { addFunctionLog } from '../../api/function-log' @@ -20,6 +19,12 @@ export async function handleDebugFunction(req: Request, res: Response) { const requestId = req['requestId'] const func_name = req.params?.name const debug_token = req.get('debug-token') ?? undefined + const func_data = req.body?.func + const param = req.body?.param + + if (!func_data) { + return res.send({ code: 1, error: 'function data not found', requestId }) + } // verify the debug token const parsed = parseToken(debug_token as string) @@ -27,20 +32,14 @@ export async function handleDebugFunction(req: Request, res: Response) { return res.status(403).send('permission denied: invalid debug token') } - // load function data from db - const funcData = await getFunctionByName(func_name) - if (!funcData) { - return res.send({ code: 1, error: 'function not found', requestId }) - } - - const func = new CloudFunction(funcData) + const func = new CloudFunction(func_data) try { // execute the func const ctx: FunctionContext = { query: req.query, files: req.files as any, - body: req.body, + body: param, headers: req.headers, method: req.method, auth: req['auth'], diff --git a/packages/system-client/src/api/func.js b/packages/system-client/src/api/func.js index 640ceeb9ca..0c61ceaf11 100644 --- a/packages/system-client/src/api/func.js +++ b/packages/system-client/src/api/func.js @@ -118,12 +118,15 @@ export function publishFunctions() { /** * Debug cloud function */ -export async function launchFunction(functionName, data, debug = false) { +export async function launchFunction(func, param, debug = false) { const appid = store.state.app.appid const res = await axios({ - url: process.env.VUE_APP_BASE_API_APP + `/${appid}/func/debug/${functionName}`, + url: process.env.VUE_APP_BASE_API_APP + `/${appid}/func/debug/${func.name}`, method: 'post', - data: data, + data: { + func, + param + }, headers: { 'debug-token': debug } diff --git a/packages/system-client/src/views/cloudfunction/debug.vue b/packages/system-client/src/views/cloudfunction/debug.vue index d4b8ee6210..acfe268f6c 100644 --- a/packages/system-client/src/views/cloudfunction/debug.vue +++ b/packages/system-client/src/views/cloudfunction/debug.vue @@ -107,7 +107,6 @@ import FunctionLogDetail from './components/FunctionLogDetail' import FunctionEditor from '@/components/FunctionEditor' import jsonEditor from '@/components/JsonEditor/param' import { getFunctionById, getFunctionLogs, launchFunction, updateFunctionCode } from '../../api/func' -import { publishFunctions } from '../../api/func' import { showError, showSuccess } from '@/utils/show' import { debounce } from 'lodash' @@ -217,8 +216,12 @@ export default { if (r.error) { return showError('保存失败!') } + this.func = r.data + this.value = this.func.code + this.invokeParams = this.parseInvokeParam(this.func.debugParams) ?? defaultParamValue + if (showTip) { - await this.getFunction() + // await this.getFunction() showSuccess('已保存: ' + this.func.name) } }, @@ -231,9 +234,8 @@ export default { if (this.loading) return this.loading = true - await publishFunctions(this.appid) const param = this.parseInvokeParam(this.invokeParams) - const res = await launchFunction(this.func.name, param, debug_token) + const res = await launchFunction(this.func, param, debug_token) .finally(() => { this.loading = false }) this.invokeRequestId = res.headers['requestid']