forked from FoundKeyGang/FoundKey
improve fetching of endpoint arguments
including support for route parameters (e.g. '/v2/note/:noteId' giving us a 'noteId' value)
This commit is contained in:
parent
aefe15e8ed
commit
4c055456d2
1 changed files with 16 additions and 5 deletions
|
@ -5,12 +5,23 @@ import authenticate, { AuthenticationError } from './authenticate.js';
|
|||
import call from './call.js';
|
||||
import { ApiError } from './error.js';
|
||||
|
||||
function getRequestArguments(ctx: Koa.Context): any {
|
||||
const args = {
|
||||
...(ctx.params || {}),
|
||||
...ctx.query,
|
||||
...(ctx.request.body || {}),
|
||||
};
|
||||
|
||||
// For security reasons, we drop the i parameter if it's a GET request
|
||||
if (ctx.method === 'GET') {
|
||||
delete args['i'];
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export default (endpoint: IEndpoint, ctx: Koa.Context) => new Promise<void>((res) => {
|
||||
const body = ctx.is('multipart/form-data')
|
||||
? (ctx.request as any).body
|
||||
: ctx.method === 'GET'
|
||||
? ctx.query
|
||||
: ctx.request.body;
|
||||
const body = getRequestArguments(ctx);
|
||||
|
||||
const reply = (x?: any, y?: ApiError) => {
|
||||
if (x == null) {
|
||||
|
|
Loading…
Reference in a new issue