From 58e83f8e4f634bfd95a3afc847a875413120c301 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 25 Jun 2022 18:26:31 +0900 Subject: feat: allow GET for some endpoints Resolve #8263 --- packages/backend/src/server/api/api-handler.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'packages/backend/src/server/api/api-handler.ts') diff --git a/packages/backend/src/server/api/api-handler.ts b/packages/backend/src/server/api/api-handler.ts index f97c3dd397..d2d16597e1 100644 --- a/packages/backend/src/server/api/api-handler.ts +++ b/packages/backend/src/server/api/api-handler.ts @@ -6,7 +6,11 @@ import call from './call.js'; import { ApiError } from './error.js'; export default (endpoint: IEndpoint, ctx: Koa.Context) => new Promise((res) => { - const body = ctx.request.body; + const body = ctx.is('multipart/form-data') + ? (ctx.req as any).body + : ctx.method === 'GET' + ? ctx.query + : ctx.request.body; const reply = (x?: any, y?: ApiError) => { if (x == null) { @@ -33,6 +37,9 @@ export default (endpoint: IEndpoint, ctx: Koa.Context) => new Promise((res authenticate(body['i']).then(([user, app]) => { // API invoking call(endpoint.name, user, app, body, ctx).then((res: any) => { + if (ctx.method === 'GET' && endpoint.meta.cacheSec && !body['i'] && !user) { + ctx.set('Cache-Control', `public, max-age=${endpoint.meta.cacheSec}`); + } reply(res); }).catch((e: ApiError) => { reply(e.httpStatusCode ? e.httpStatusCode : e.kind === 'client' ? 400 : 500, e); -- cgit v1.2.3-freya