summaryrefslogtreecommitdiff
path: root/packages/backend/src
diff options
context:
space:
mode:
authorKagami Sascha Rosylight <saschanaz@outlook.com>2022-12-19 15:57:36 +0900
committerGitHub <noreply@github.com>2022-12-19 15:57:36 +0900
commitc3cb2189753aa74b8fc5c554577deeed89971dc6 (patch)
tree3de8a3ffdc8a5a93d08540f34a909c78fae834f6 /packages/backend/src
parentfix(cypress): pass `{}` as a parameter for `/api/reset-db` (#9355) (diff)
downloadsharkey-c3cb2189753aa74b8fc5c554577deeed89971dc6.tar.gz
sharkey-c3cb2189753aa74b8fc5c554577deeed89971dc6.tar.bz2
sharkey-c3cb2189753aa74b8fc5c554577deeed89971dc6.zip
fix(backend): request.body may be undefined (#9356)
Diffstat (limited to 'packages/backend/src')
-rw-r--r--packages/backend/src/server/api/ApiCallService.ts10
1 files changed, 5 insertions, 5 deletions
diff --git a/packages/backend/src/server/api/ApiCallService.ts b/packages/backend/src/server/api/ApiCallService.ts
index 8cc7382c58..9d45a49c09 100644
--- a/packages/backend/src/server/api/ApiCallService.ts
+++ b/packages/backend/src/server/api/ApiCallService.ts
@@ -54,21 +54,21 @@ export class ApiCallService implements OnApplicationShutdown {
@bindThis
public handleRequest(
endpoint: IEndpoint & { exec: any },
- request: FastifyRequest<{ Body: Record<string, unknown>, Querystring: Record<string, unknown> }>,
+ request: FastifyRequest<{ Body: Record<string, unknown> | undefined, Querystring: Record<string, unknown> }>,
reply: FastifyReply,
) {
const body = request.method === 'GET'
? request.query
: request.body;
- const token = body['i'];
+ const token = body?.['i'];
if (token != null && typeof token !== 'string') {
reply.code(400);
return;
}
this.authenticateService.authenticate(token).then(([user, app]) => {
this.call(endpoint, user, app, body, null, request).then((res) => {
- if (request.method === 'GET' && endpoint.meta.cacheSec && !body['i'] && !user) {
+ if (request.method === 'GET' && endpoint.meta.cacheSec && !body?.['i'] && !user) {
reply.header('Cache-Control', `public, max-age=${endpoint.meta.cacheSec}`);
}
this.send(reply, res);
@@ -111,7 +111,7 @@ export class ApiCallService implements OnApplicationShutdown {
for (const [k, v] of Object.entries(multipartData.fields)) {
fields[k] = v.value;
}
-
+
const token = fields['i'];
if (token != null && typeof token !== 'string') {
reply.code(400);
@@ -199,7 +199,7 @@ export class ApiCallService implements OnApplicationShutdown {
name: string;
path: string;
} | null,
- request: FastifyRequest<{ Body: Record<string, unknown>, Querystring: Record<string, unknown> }>,
+ request: FastifyRequest<{ Body: Record<string, unknown> | undefined, Querystring: Record<string, unknown> }>,
) {
const isSecure = user != null && token == null;
const isModerator = user != null && (user.isModerator || user.isAdmin);