diff --git a/runtimes/nodejs/src/handler/debug-func.ts b/runtimes/nodejs/src/handler/debug-func.ts index 4a28f40745..bd5a0baeb4 100644 --- a/runtimes/nodejs/src/handler/debug-func.ts +++ b/runtimes/nodejs/src/handler/debug-func.ts @@ -11,6 +11,7 @@ import { logger } from '../support/logger' import { CloudFunction } from '../support/function-engine' import { IRequest } from '../support/types' import { parseToken } from '../support/token' +import { ICloudFunctionData } from '@lafjs/cloud' /** * Handler of debugging cloud function @@ -26,10 +27,22 @@ export async function handleDebugFunction(req: IRequest, res: Response) { return res.status(403).send('permission denied: invalid debug token') } + // get func_data from header + const func_str = req.get('x-laf-func-data') + if (!func_str) { + return res.status(400).send('x-laf-func-data is required') + } + + // parse func_data + let func_data: ICloudFunctionData + try { + func_data = JSON.parse(func_str) + } catch (error) { + return res.status(400).send('x-laf-func-data is invalid') + } + const requestId = req['requestId'] const func_name = req.params?.name - 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 }) @@ -42,12 +55,13 @@ export async function handleDebugFunction(req: IRequest, res: Response) { const ctx: FunctionContext = { query: req.query, files: req.files as any, - body: param, + body: req.body, headers: req.headers, method: req.method, auth: req.user, user: req.user, requestId, + request: req, response: res, __function_name: func.name, } diff --git a/web/src/pages/app/functions/mods/DebugPannel/index.tsx b/web/src/pages/app/functions/mods/DebugPannel/index.tsx index 75e1986f08..afaf9cd1d2 100644 --- a/web/src/pages/app/functions/mods/DebugPannel/index.tsx +++ b/web/src/pages/app/functions/mods/DebugPannel/index.tsx @@ -80,15 +80,15 @@ export default function DebugPanel() { name: currentFunction!.name, }); if (!compileRes.error) { + const func_data = JSON.stringify(compileRes.data); + const body_params = JSON.parse(params); const res = await axios({ url: getFunctionDebugUrl(), method: runningMethod, - data: { - func: compileRes.data || "", - param: JSON.parse(params), - }, + data: body_params, headers: { "x-laf-debug-token": `${globalStore.currentApp?.function_debug_token}`, + "x-laf-func-data": func_data, }, });