From 00708b97cadf62f026112db79e13701128cbf8a5 Mon Sep 17 00:00:00 2001 From: Beng Eu Date: Tue, 13 Jul 2021 16:29:22 +0800 Subject: [PATCH 1/3] Encapsulate routes in separate plugins So that changes to the Fastify instance will only be reflected in each plugin's scope. --- src/routes/bucket/index.ts | 12 ++++++------ src/routes/object/index.ts | 22 +++++++++++----------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/routes/bucket/index.ts b/src/routes/bucket/index.ts index 8a0f3463..858dd1b4 100644 --- a/src/routes/bucket/index.ts +++ b/src/routes/bucket/index.ts @@ -8,10 +8,10 @@ import updateBucket from './updateBucket' // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types export default async function routes(fastify: FastifyInstance) { - createBucket(fastify) - deleteBucket(fastify) - emptyBucket(fastify) - getAllBuckets(fastify) - getBucket(fastify) - updateBucket(fastify) + fastify.register(createBucket) + fastify.register(deleteBucket) + fastify.register(emptyBucket) + fastify.register(getAllBuckets) + fastify.register(getBucket) + fastify.register(updateBucket) } diff --git a/src/routes/object/index.ts b/src/routes/object/index.ts index e7efc921..74e45db3 100644 --- a/src/routes/object/index.ts +++ b/src/routes/object/index.ts @@ -13,15 +13,15 @@ import updateObject from './updateObject' // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types export default async function routes(fastify: FastifyInstance) { - copyObject(fastify) - createObject(fastify) - deleteObject(fastify) - deleteObjects(fastify) - getObject(fastify) - getSignedObject(fastify) - getPublicObject(fastify) - getSignedURL(fastify) - moveObject(fastify) - updateObject(fastify) - listObjects(fastify) + fastify.register(copyObject) + fastify.register(createObject) + fastify.register(deleteObject) + fastify.register(deleteObjects) + fastify.register(getObject) + fastify.register(getSignedObject) + fastify.register(getPublicObject) + fastify.register(getSignedURL) + fastify.register(moveObject) + fastify.register(updateObject) + fastify.register(listObjects) } From d36e32a1bf0ee5e163ee7ec19f0e5ad63815bf3d Mon Sep 17 00:00:00 2001 From: Beng Eu Date: Tue, 13 Jul 2021 15:02:12 +0800 Subject: [PATCH 2/3] fix: #43 use custom content type parser for application/json and text/plain Pipe the request stream for these content types instead of the default handling. See https://www.fastify.io/docs/latest/ContentTypeParser/. --- src/routes/object/createObject.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/routes/object/createObject.ts b/src/routes/object/createObject.ts index c9dc3e1d..15a628c2 100644 --- a/src/routes/object/createObject.ts +++ b/src/routes/object/createObject.ts @@ -49,6 +49,13 @@ export default async function routes(fastify: FastifyInstance) { tags: ['object'], }) + fastify.addContentTypeParser( + ['application/json', 'text/plain'], + function (request, payload, done) { + done(null) + } + ) + fastify.post( '/:bucketName/*', { From e3b8a0d2e8a0ab16cdd6b4a276e0e18cbe524e0e Mon Sep 17 00:00:00 2001 From: Inian Date: Thu, 15 Jul 2021 12:54:24 +0800 Subject: [PATCH 3/3] fix: use custom content type parser in updateObject too --- src/routes/object/updateObject.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/routes/object/updateObject.ts b/src/routes/object/updateObject.ts index 2421d989..de8571be 100644 --- a/src/routes/object/updateObject.ts +++ b/src/routes/object/updateObject.ts @@ -44,6 +44,14 @@ export default async function routes(fastify: FastifyInstance) { summary, tags: ['object'], }) + + fastify.addContentTypeParser( + ['application/json', 'text/plain'], + function (request, payload, done) { + done(null) + } + ) + fastify.put( '/:bucketName/*', {