Skip to content

Commit 80c0bd8

Browse files
committed
fix(http): changes to fastify content parsers
1 parent 2aedabf commit 80c0bd8

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

oada/libs/lib-arangodb/src/libs/putBodies.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,9 @@ const collection = database.collection<{body: unknown}>(
2626
* Give string of JSON rather than object
2727
*/
2828
export async function savePutBody(body: string): Promise<{ _id: string }> {
29-
// HACK: send body without parsing it
30-
const cursor = await database.query<string>({
31-
query: `
32-
INSERT ${body}
33-
INTO ${collection.name}
34-
RETURN NEW._id
35-
`,
36-
bindVars: {},
37-
});
38-
return { _id: (await cursor.next())! };
29+
// @ts-expect-error HACK: send body without parsing it
30+
const { _id } = await collection.save(`body:${body}`);
31+
return { _id };
3932
}
4033

4134
export async function getPutBody(id: string): Promise<unknown> {

oada/services/http-handler/src/resources.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,21 @@ const plugin: FastifyPluginAsync<Options> = async (fastify, options) => {
416416

417417
// Parse JSON content types as text (but do not parse JSON yet)
418418
fastify.addContentTypeParser(
419-
['json', '+json'],
419+
['application/json', 'text/json'],
420+
{
421+
// FIXME: Stream process the body instead
422+
parseAs: 'string',
423+
// 20 MB
424+
bodyLimit: 20 * 1_048_576,
425+
},
426+
(_, body, done) => {
427+
// eslint-disable-next-line unicorn/no-null
428+
done(null, body);
429+
},
430+
);
431+
fastify.addContentTypeParser(
432+
// application/*+json
433+
/^application\/([\w\.-]+)\+json(\;|$)/,
420434
{
421435
// FIXME: Stream process the body instead
422436
parseAs: 'string',

0 commit comments

Comments
 (0)