Skip to content

Commit

Permalink
fix(runtime): add func data header for debug api, support multiple-me…
Browse files Browse the repository at this point in the history
…thod for debug request (#594)
  • Loading branch information
maslow authored Jan 1, 2023
1 parent 03846e7 commit db9eacd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
20 changes: 17 additions & 3 deletions runtimes/nodejs/src/handler/debug-func.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 })
Expand All @@ -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,
}
Expand Down
8 changes: 4 additions & 4 deletions web/src/pages/app/functions/mods/DebugPannel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
});

Expand Down

0 comments on commit db9eacd

Please sign in to comment.