Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime): add func data header for debug api, support multiple-method for debug request #594

Merged
merged 1 commit into from
Jan 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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