Comments (4)
@lmammino 🤔 🤝
from middy.
Thanks @vladgolubev, that's probably a good idea. I think we have to make this middleware slightly smarter to handle this case (and more).
The original idea of having it in the after
phase was to make sure that the user does not override it by mistake, but we didn't think it might have affected error cases.
One idea could be to set the callbackWaitsForEmptyEventLoop
to false in both phases (before
and after
) and probably we should do it also in the onError
phase.
Also, we could assume the before
phase is mandatory and the after
and onError
phases could be switched off through config.
Using these ideas, this can be a first draft of the new version:
module.exports = (opts) => {
const defaults = {
runOnAfter: true,
runOnError: true
}
const options = Object.assign({}, defaults, opts)
const setFlag = (handler, next) => {
handler.context.callbackWaitsForEmptyEventLoop = false
next()
}
return ({
before: setFlag,
after: options.runOnAfter ? setFlag : undefined,
onError: options.runOnError ? setFlag : undefined
})
}
@dkatavic, what do you think?
from middy.
That makes totally sense @dkatavic. Thanks!
Probably we should also set more efficient defaults like:
const defaults = {
runOnBefore: true,
runOnAfter: false, // user code (or other middlewares) might reset the flag, but no extra function is executed
runOnError: false // user code (or other middlewares) might reset the flag, but no extra function is executed
}
@vladgolubev, do you want to take care of submitting a PR with this? 😉
from middy.
Good catch @vladgolubev . I like the draft @lmammino , just I would like to make the middleware as configurable as possible, so can we add runOnBefore
option too?
from middy.
Related Issues (20)
- Fetching SSM params: InvalidSignatureException: Signature expired HOT 12
- Version 6 [Draft]
- Logo is weird on MacOS Safari
- Json body parser unusable with typescript, typing errors within the package HOT 4
- Missing type-utils.d.ts file in @middy/util package HOT 8
- Streamed responses giving 502 Bad Gateway when payload exceeds threshold (25kb+) HOT 8
- How to use version 5 with TypeScript HOT 4
- http-response-serializer documentation incorrect HOT 1
- Typescript error in handler parameters HOT 4
- Module not found: Error: Package path . is not exported from package HOT 1
- Response validation not working HOT 4
- Use @fastify/busboy instead of outdated busboy HOT 2
- Type middy.MiddlewareFn doesn't exist HOT 17
- Cannot find module '@middy/core' when running jest with typescript and esm HOT 15
- ERR_PACKAGE_PATH_NOT_EXPORTED HOT 2
- @middy/dynamodb middleware: Unmarshall on empty item is causing exception HOT 3
- The `inputOutputLogger` middleware fails if used with a streaming handler. HOT 2
- Matching `Access-Control-Allow-Headers` HOT 5
- Documentation: Enable middlewares based on request event parameters HOT 3
- Http router / path mapping HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from middy.