-
-
Notifications
You must be signed in to change notification settings - Fork 685
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cloud-func): support unpublished func debugging
- Loading branch information
Showing
3 changed files
with
21 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
/* | ||
* @Author: Maslow<[email protected]> | ||
* @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,27 +19,27 @@ 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) | ||
if (!parsed || parsed.type !== 'debug') { | ||
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'], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters