redwoodjs / redwood

The App Framework for Startups
https://redwoodjs.com
MIT License
17.14k stars 979 forks source link

Possibly use middy.js for serverless middleware? #398

Open chris-hailstorm opened 4 years ago

chris-hailstorm commented 4 years ago

One of the things I miss from Express / Koa is the middleware approach and big ecosystem of pre-built middleware. I've been thinking about how to replace Helmet, loggers, etc. in Redwood.

Middy looks like a solid option for Lambda middleware. Good intro at https://middy.js.org/.

Question: has anyone thought about Redwood middleware? Middy could be a foundation.

And then if we're really smart, maybe we can figure out how to wrap / transform existing Express and Koa middleware libraries so they work in Middy. Fast-track to a big ecosystem.

thedavidprice commented 4 years ago

@chris-hailstorm Have you had a chance to take Middy for a test drive? Example they provide seems very straight forward. I’m sure there’s something I’m missing, but it looks like Redwood’s Services will play nicely.

Thinking out loud —> we’ve often discussed creating an Emailer Service integration example (something like Sendgrid). Might that be a good test case? Or, if not, something else along those lines?

willfarrell commented 2 years ago

Let me know if you have any questions about middy. We have v3 releasing in the coming months :).

thedavidprice commented 2 years ago

Hi @willfarrell Thank you for the offer. Right now we are in the middle of a release candidate cycle leading up to a 1.0.0 GA in a couple months. So we're not focused on adding new features or capability. But middy definitely looks interesting! I'd be curious to know if middy JustWorks™ with Redwood or if build-in support is necessary. If the former, then it might be a great opportunity to create an official guide to post with our docs.

I did look (briefly) though the middy docs. One thing to note about Redwood is that there's already built in handling to the following types of logic via Redwood Services (i.e. validators) and GraphQL (i.e. directives):

Anyway, when you are writing a handler, you still have to deal with some common technical concerns outside business logic, like input parsing and validation, output serialization, error handling, etc.

But that doesn't mean middy wouldn't be helpful.

No pressure here and no rush on the timing, but if you'd be interested in working up a quick POC I know the team would love to take a look.

willfarrell commented 2 years ago

I've been reading through the serverless-fucntions documentation, as I don't use redwood myself. It looks like middy is a drop in benefit add (JustWorks™). Middy if fully modular, so you only need to add the middlewares that meet your needs :). We have most AWS Events supported with example patterns for each, giving you a head start on picking.

We're also prepping for a v3 release in a couple months. We're just waiting on nodejs v16 support (Likely early Apr). In case someone is interested in starting the scoping early, our upgrade guide is already drafted (https://github.com/middyjs/middy/blob/release/3.x/docs/UPGRADE.md).

thedavidprice commented 2 years ago

@willfarrell This is all great to know. And good luck with the v3 release!

Our hands are full getting to our own v1 release in a couple months. We'd welcome any POCs or docs/cookbooks showing and example use. But no pressure or expectation.

Could also make for a great community contribution if/when anyone is ever interested. Just let us know.