Skip to content

Commit

Permalink
feat(app-service): support default cloud function (#117 #115)
Browse files Browse the repository at this point in the history
  • Loading branch information
skyoct authored May 24, 2022
1 parent bf772d2 commit 04b7320
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/app-service/src/handler/invoke-func.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { logger } from '../support/logger'
import { addFunctionLog } from '../support/function'
import { CloudFunction } from '../support/function'

const DEFAULT_FUNCTION_NAME = '__default__'

/**
* Handler of invoking cloud function
Expand All @@ -21,12 +22,17 @@ export async function handleInvokeFunction(req: Request, res: Response) {
const func_name = req.params?.name

// load function data from db
const funcData = await CloudFunction.getFunctionByName(func_name)
let funcData = await CloudFunction.getFunctionByName(func_name)
if (!funcData) {
if (func_name === 'healthz') {
return res.status(200).send('ok')
}
return res.status(404).send('Not Found')

// load default function from db
funcData = await CloudFunction.getFunctionByName(DEFAULT_FUNCTION_NAME)
if (!funcData) {
return res.status(404).send('Not Found')
}
}

const func = new CloudFunction(funcData)
Expand Down

0 comments on commit 04b7320

Please sign in to comment.