Skip to content

Commit

Permalink
fix(http): changes to fastify content parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
awlayton committed Dec 12, 2024
1 parent 2aedabf commit 80c0bd8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
13 changes: 3 additions & 10 deletions oada/libs/lib-arangodb/src/libs/putBodies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,9 @@ const collection = database.collection<{body: unknown}>(
* Give string of JSON rather than object
*/
export async function savePutBody(body: string): Promise<{ _id: string }> {
// HACK: send body without parsing it
const cursor = await database.query<string>({
query: `
INSERT ${body}
INTO ${collection.name}
RETURN NEW._id
`,
bindVars: {},
});
return { _id: (await cursor.next())! };
// @ts-expect-error HACK: send body without parsing it
const { _id } = await collection.save(`body:${body}`);
return { _id };
}

export async function getPutBody(id: string): Promise<unknown> {
Expand Down
16 changes: 15 additions & 1 deletion oada/services/http-handler/src/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,21 @@ const plugin: FastifyPluginAsync<Options> = async (fastify, options) => {

// Parse JSON content types as text (but do not parse JSON yet)
fastify.addContentTypeParser(
['json', '+json'],
['application/json', 'text/json'],
{
// FIXME: Stream process the body instead
parseAs: 'string',
// 20 MB
bodyLimit: 20 * 1_048_576,
},
(_, body, done) => {
// eslint-disable-next-line unicorn/no-null
done(null, body);
},
);
fastify.addContentTypeParser(
// application/*+json
/^application\/([\w\.-]+)\+json(\;|$)/,
{
// FIXME: Stream process the body instead
parseAs: 'string',
Expand Down

0 comments on commit 80c0bd8

Please sign in to comment.