Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 02:19
    willfarrell labeled #736
  • Oct 16 12:19
    Kelvijn opened #736
  • Oct 15 14:08
    omer-to opened #735
  • Oct 14 14:33
    onhate commented #473
  • Oct 13 20:43
    joeythomaschaske commented #473
  • Oct 13 20:43
    joeythomaschaske commented #473
  • Oct 13 14:52
    omer-to opened #734
  • Oct 12 19:34
    sidharth-shridhar commented #731
  • Oct 12 19:33
    sidharth-shridhar closed #731
  • Oct 12 19:33
    sidharth-shridhar commented #731
  • Oct 12 15:50

    willfarrell on 2.5.2

    (compare)

  • Oct 12 15:50

    willfarrell on main

    chore: update deps (compare)

  • Oct 12 15:44

    willfarrell on main

    Add missing parameter for reque… Merge pull request #733 from om… (compare)

  • Oct 12 15:44
    willfarrell closed #733
  • Oct 10 19:19
    omer-to opened #733
  • Oct 10 02:51
    willfarrell commented #732
  • Oct 09 22:35
    omer-to commented #732
  • Oct 09 02:15
    willfarrell commented #731
  • Oct 09 02:09
    willfarrell commented #731
  • Oct 09 02:04
    sidharth-shridhar commented #731
will Farrell
@willfarrell
If anyone is in Calgary, be sure to hit me up.
Yoni Braslaver
@JoniBR
Hi, I have an issue where I throw an error object in one of the middlewares but on the onError function handler.error only holds the object.message property. any way to access the full object on the onError?
will Farrell
@willfarrell
Has anyone played around with Streaming json from lambda to oboejs or similar? Having trouble finding it in the documentation, is it called StreamingBody?
Alper Necati Akin
@alpernakin
Hello folk!
Does anybody know how to assign error message for validation on input schema object?
will Farrell
@willfarrell
Check out https://github.com/epoberezkin/ajv-errors, might be what you're looking for.
will Farrell
@willfarrell
We made the news. The top story in Node Weekly https://nodeweekly.com/issues/336
will Farrell
@willfarrell
will Farrell
@willfarrell
and serverless weekly: https://serverless.email/issues/148 really making the rounds.
Callum Evans
@callumevans

Hey all! Is there any preferred way of reusing a configured set of middlewares?

I have a handler configured:

const handler = middy(async (event, context, callback) => {
    (...)
    callback(null, { });
});

handler.use(middleware1())
handler.use(middleware2())
handler.use(middleware3())
handler.use(middleware4())

module.exports = { handler };

I'm looking for a good way of only having to specify something like:

const handler = withMiddlewares(async (event, context, callback) => {
    (...)
    callback(null, { });
});

module.exports = { handler };

Where the handler is pre-configured with a bunch of middlewares.

I'm trying to avoid duplicating a bunch of handler configurations that are all going to be the same / similar.

Cheers!

Luciano Mammino
@lmammino
Hey @callumevans, .use() also supports array of middlewares. If I understand your question, that might help you to simplify reusing pre-configured middlewares across handlers
Andrey Alyabyev
@nodeleaks
Hi everyone! Is it possible to trigger middleware by another middleware? Help please with example
will Farrell
@willfarrell
Can you describe your use case in more detail? All middlewares get triggered, if you wanted to disable/enable one based on the context you would have to write your own wrapper to handle that.
Andrey Alyabyev
@nodeleaks
I found that return handler.callback() stops function's execution immediately and return next() just stop middleware execution. Thats what I need
Linus Probert
@LiquidityC
Hi guys. I've working on a api call where the caller needs to provide either "department" or "email" eg. one has to be present but not both. Does middy have support for such a scenario? Before you ask, no, I can't change it (which obviously might be better)
will Farrell
@willfarrell
@LiquidityC when using the validator middleware (which uses ajv) depends on JSON Schema which supports that. Checkout oneOf in the spec.
Linus Probert
@LiquidityC
@willfarrell Will do, thanks man!
Erick Peniche
@erickpeniche
Hi! I'm having some issues while working with middy and httpErrorHandler middleware. I am using AWS Lambdas through an API Gateway, I have wrapped my handler in a middy() function and also applied the middlewares with .use(). When I need to throw an error inside my Lambda handler, I use the createError method from the http-errors library. But for some reason, the lambda response is always a 502 with {"message": "Internal server error"}. Am I missing something?
will Farrell
@willfarrell
The httpErrorHandler should be the last middleware in the chain. Can't really help more without seeing the full example. Maybe post an issue in the repo.
David Vasandani
@davidvasandani
Is it possible to run middy-reroute locally for testing?
Martin Donath
@squidfunk
Hey there! Big fan of middy.js - it takes so much pain away. I was wondering if there's a standard approach to routing, i.e. one Lambda function that serves several of API endpoints with different handlers depending on the .routeKey (or .httpMethod + .resource)? Searching for router or routing on the issue tracker returns nothing.
Martin Muller
@mmuller88
Hi fellaws. First of all thank you so much for the amazing middy libraries <3. Just started some days ago using them. Is that the official community room :)?
Emanuele Ricci
@StErMi
hi everyone, I'm new to middy and I would like to create an official middleware for MikroORM (a typescript ORM I'm using). I'm using typescript on my project but I cannot find no typescript example on how to correctly use a middleware with typings and lambda or an example of custom middleware developed with typescript. Is there someone that has already did that and can share some example/process?
Martin Muller
@mmuller88
@StErMi I think in the issues page was some examples given :). But yeah I made good experience with just taking the JavaScript stuff TypeScript and solving occuring problems :)
Emanuele Ricci
@StErMi
uhm so real existing examples? :(
Martin Muller
@mmuller88

Yeah I think that ones mentioned here are good middyjs/middy#373

Bur rather complicated ^^

Emanuele Ricci
@StErMi
mmm I'm tying a little bit do do those but to be host they are not complete and some of them I think their using an old version of middy. I would like to see a full example that rely on both Event and Context
Emanuele Ricci
@StErMi
how should I correctly throw http exception from middy middleware in a format designed by me?
Emanuele Ricci
@StErMi
if I'm using typescript and I'm also using jsonBodyParser is there something that extends APIGatewayEvent and add the body as a JSON object?
will Farrell
@willfarrell
Happy New Year everyone! It's been a growing year for Middy with lots of adoptions (see below). Thank you for all of your help over the past year in making middy better than ever. We have some great news to start the year off with; I've started working on middy v2. We're addressing some of your most requested features and performance bottlenecks but will need to make some breaking changes. My goal is to have something together over the coming month so the community can comment. I'm hopeful AWS will support Node.js v14 around Apr/May and plan to have an alpha release ready for then.

Full trend details at middyjs/middy#590
Martin Muller
@mmuller88
Happy new Year. Amazing news I am very excited :)
will Farrell
@willfarrell
If you want to follow what's happing with v2, subscribe to this issue: middyjs/middy#585.
1 reply
Yang Yang
@zacyang
Hi all, I just switched my middy handle from the old (e,c, cb)=> {}. to async function, but , the original lambda function stoped return content (AWS lambda), is there some additional middleware I have to add to use async handler?
will Farrell
@willfarrell
@zacyang Thanks for reaching out. Changing from callback to promise does also require you to return the response instead of using the callback function. There is an example in the README. This is a common pain point for many. We've rebuilt middy to remove the callback option in v2 to make this easier for all. We hope to have an alpha out in the next week (you can check it out sooner on the release/v2 branch). Plans to have it released after AWS supports Node.js v14.
will Farrell
@willfarrell
1 reply
Luciano Mammino
@lmammino
middy 2.0 is there!
Davide Behr
@behr-davide
Quick question.. can code outside of a handler function use parameters loaded by the SSM middleware? I logged the process.env object outside of my handler and it did not contain the SSM param I fetched.
will Farrell
@willfarrell
In v1 you need to consider when things are triggered in the event cycle. So, yes it can. Saving to context should make it easier. In v2 there is an all-new internal object that can be used to share data between middleware securely and asynchronously to make these usecases easier.
Davide Behr
@behr-davide
Good to know -- thanks for your response and thank you to everyone who contributes to middy! :pray:
Luciano Mammino
@lmammino
Voxel Group has just announced a port of middy to the .net runtime: https://twitter.com/vgaltes/status/1366371605337825284
will Farrell
@willfarrell
Middy passed 100k downloads per week. Crazyness. https://www.npmtrends.com/@middy/core-vs-middy
Oh yeah, v2 beta is now releaseed :)
Luciano Mammino
@lmammino
WOOW great news!
Luciano Mammino
@lmammino
will Farrell
@willfarrell
I was wondering how they allowed "streaming" file changes since lambda doesn't support streamed responses. Not a fan of the pattern their using, I think we could make this much better. I was hoping they would pass in a read stream and we could return a transform stream. I'll for sure use this feature once terraform supports it. I see a lot of value in having a middleware for this to make it way easier.
Luciano Mammino
@lmammino
I had the exact same thought and I was a bit disappointed too :D However, from what i have seen in the api to create a custom lambda executor, I think doing a streaming implementation for Node.js could be feasible. I had a look sometime ago but if I remember correclty in that abstraction you have access to raw http requests, therefore you should be able to access streaming requests and provide streaming responses...
will Farrell
@willfarrell
Seriously, this is possible now? I've been waiting for streaming responses since apig was introduced. We have to add this to middy :P
Luciano Mammino
@lmammino
I might have to experiment a little with creating a non-standard executor