accept api parameters via GET

Massimo Melina committed Dec 21, 2021 at 23:50 UTC 1bbee1f1a75d250156362e1850e60793042205f3
1 file changed +3 -1
src/apis.ts
+3 -1
@@ -13,7 +13,7 @@ type ApiHandlers = Record<string, ApiHandler>
13
14 export function apiMw(apis: ApiHandlers) : Koa.Middleware {
15 return async (ctx, next) => {
16 - const params = ctx.request.body
16 + const params = ctx.method === 'POST' ? ctx.request.body : ctx.request.query
17 console.debug('API', ctx.method, ctx.path, params)
18 if (!(ctx.path in apis))
19 return ctx.throw(404, 'invalid api')
@@ -45,6 +45,8 @@ export const frontEndApis: ApiHandlers = {
45 return
46 if (search?.includes('..'))
47 return ctx.throw(400)
48 + offset = Number(offset)
49 + limit = Number(limit)
50 const re = new RegExp(_.escapeRegExp(search),'i')
51 const match = (s?:string) => !s || !search || re.test(s)
52 const who = await getCurrentUser(ctx) // cache value