redwood
redwood copied to clipboard
feat: add customize content type parsers for api plugin
This PR allows users to extend supported contentType for native API plugin. I follow https://redwoodjs.com/docs/docker#using-the-server-file, but it doesn't work.
...
await server.register(redwoodFastifyAPI, { <-- work after remove "await"
redwood: {
apiRootPath,
fastGlobOptions: {
ignore: ['**/dist/functions/graphql.js'],
},
},
})
...
// This doesn't work after a "await server.register(...)"
server.addContentTypeParser('text/csv', { parseAs: 'string' }, (request, body, done) => {
const csvData = body.split('\n').map(row => row.split(','))
done(null, csvData)
})
- ref: https://fastify.dev/docs/v2.15.x/Documentation/ContentTypeParser/#content-type-parser
- ref: https://redwoodjs.com/docs/docker#using-the-server-file
- ref: https://github.com/fastify/fastify/issues/5401
- ref: https://fastify.dev/docs/latest/Reference/Plugins/#asyncawait
Thanks for your PR @scott1028 I'm sorry no one got back to you sooner. We'll discuss this internally and see who can help move this forward
Thanks for your PR @scott1028 I'm sorry no one got back to you sooner. We'll discuss this internally and see who can help move this forward
Thanks for your reply :)
@scott1028 I found someone who can look into this. He's busy with other things right now, but will get to this when he has some more time available
Hey @scott1028 👋 Again sorry for the radio silence on this. I'll get to this one in the next day or two
Hey @scott1028 👋 Again sorry for the radio silence on this. I'll get to this one in the next day or two
updated test.
@scott1028 Thanks for your effort on this PR!
We've been discussing this PR internally and have a couple of things I wanted to bring up.
-
We decided we wanted to explore some alternative ways of implementing this.
-
We think the naming of the parameter could benefit from some additional thought. Could you please help us with some alternative names? Something that makes it more clear what it is, what it does and how it's supposed to be used.
@Tobbe Thanks for reply.
- We decided we wanted to explore some alternative ways of implementing this.
Need I work on this PR if you guys want to implement the same somehow?
- We think the naming of the parameter could benefit from some additional thought. Could you please help us with some alternative names? Something that makes it more clear what it is, what it does and how it's supposed to be used.
hmm, I will name it something like preCustomizeAPI
, customizeAPI
etc, because it's executed before await server.register(redwoodFastifyAPI, ...
. I just want expose a interface for developer to mutate the fasitfy
instance.
Need I work on this PR if you guys want to implement the same somehow?
No, nothing for you to do right now 🙂 We'll get back to you with how to move forward next week
Sorry it's take me longer than expected to get to this. I'm going to look through this now. One thing that might help me understand better is where you had been planing on using this additional content parser within your project?
@scott1028 and @Tobbe - I didn't have permission to push to your fork @scott1028 so I had to open a new PR in the redwood repo: https://github.com/redwoodjs/redwood/pull/10573. This uses your original approach but just renames and moves things around a little.
I'm happy with this approach until we decide we need to rework things in a more destructive way. @Tobbe might have naming or other decisions to make but I'd love to know what you think @scott1028 if this is okay and works for your problem?
Sorry it's take me longer than expected to get to this. I'm going to look through this now. One thing that might help me understand better is where you had been planing on using this additional content parser within your project?
Yes. That's what I found the problem and I want to resolve after I surveyed fastify. :)
I'm happy with this approach until we decide we need to rework things in a more destructive way. @Tobbe might have naming or other decisions to make but I'd love to know what you think @scott1028 if this is okay and works for your problem?
It's great and works for me. Thanks.
@Josh-Walker-GM can we close this in favor of your PR?
@Josh-Walker-GM can we close this in favor of your PR?
yes. I think we can just use https://github.com/redwoodjs/redwood/pull/10573
use https://github.com/redwoodjs/redwood/pull/10573