Skip to content

Commit

Permalink
fix(Awala): Take CloudEvent content type from actual event (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnarea authored Jul 9, 2023
1 parent 96f0ba5 commit e2152ab
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ src/**.js
coverage
**/.DS_Store


docs/.bundle
docs/.jekyll-cache
docs/.sass-cache
Expand Down
12 changes: 5 additions & 7 deletions src/awala/routes/awala.routes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { CloudEventV1 } from 'cloudevents';
import type { RouteOptions } from 'fastify';

import { HTTP_STATUS_CODES } from '../../utilities/http.js';
Expand Down Expand Up @@ -125,13 +126,7 @@ export default function registerRoutes(
url: '/',

async handler(request, reply): Promise<void> {
const contentType = awalaRequestMessageTypeList.find(
(messageType) => messageType === request.headers['content-type'],
);

const processor = awalaEventToProcessor[contentType!];

let event;
let event: CloudEventV1<unknown>;
try {
event = convertMessageToEvent(request.headers, request.body as Buffer);
} catch (err) {
Expand All @@ -148,6 +143,8 @@ export default function registerRoutes(
return reply.status(HTTP_STATUS_CODES.BAD_REQUEST).send();
}

const contentType = event.datacontenttype as AwalaRequestMessageType;
const processor = awalaEventToProcessor[contentType];
const didSucceed = await processor(incomingMessage, ceEmitter, {
logger: parcelAwareLogger,
dbConnection: this.mongoose,
Expand All @@ -160,5 +157,6 @@ export default function registerRoutes(
return reply.code(HTTP_STATUS_CODES.BAD_REQUEST).send();
},
});

done();
}

0 comments on commit e2152ab

Please sign in to comment.