diff --git a/functions/src/api.ts b/functions/src/api.ts index 8c01ea05..74203f17 100644 --- a/functions/src/api.ts +++ b/functions/src/api.ts @@ -99,12 +99,12 @@ export const validate = (schema: T, val: unknown) => { } } -interface EndpointOptions extends HttpsOptions { - methods?: string[] +export interface EndpointOptions extends HttpsOptions { + method?: string } const DEFAULT_OPTS = { - methods: ['POST'], + method: 'POST', minInstances: 1, concurrency: 100, memory: '2GiB', @@ -117,9 +117,8 @@ export const newEndpoint = (endpointOpts: EndpointOptions, fn: Handler) => { return onRequest(opts, async (req, res) => { log('Request processing started.') try { - if (!opts.methods.includes(req.method)) { - const allowed = opts.methods.join(', ') - throw new APIError(405, `This endpoint supports only ${allowed}.`) + if (opts.method !== req.method) { + throw new APIError(405, `This endpoint supports only ${opts.method}.`) } const authedUser = await lookupUser(await parseCredentials(req)) log('User credentials processed.') diff --git a/functions/src/health.ts b/functions/src/health.ts index 938261db..4ce04e05 100644 --- a/functions/src/health.ts +++ b/functions/src/health.ts @@ -1,6 +1,6 @@ import { newEndpoint } from './api' -export const health = newEndpoint({ methods: ['GET'] }, async (_req, auth) => { +export const health = newEndpoint({ method: 'GET' }, async (_req, auth) => { return { message: 'Server is working.', uid: auth.uid,