Coder Social home page Coder Social logo

Support Async Middleware about kraken-js HOT 6 OPEN

xjamundx avatar xjamundx commented on May 27, 2024 2
Support Async Middleware

from kraken-js.

Comments (6)

dougwilson avatar dougwilson commented on May 27, 2024 1

Perhaps Express can add a hook to register a function to wrap middleware, which could be used to automatically wrap the middleware / handers for this and whatever other purposes. The details for how the interaction will be done with routers will need to be hammered out, but a high-level idea is:

app.wrap(function (fn) {
  return function (req, res, next) {
    fn(req, res, next).catch(next)
  }
})

This is very high-level thought, but figured I'd start a discussion here from the comment in Express repo to get a feeling of if this could be a solution or not.

from kraken-js.

xjamundx avatar xjamundx commented on May 27, 2024 1

@dougwilson I think at this stage with async/await finally built-in to the platform, it should just become a core express/kraken feature to support promise-based middleware (without even having to opt-in via app.wrap).

It sounds like express 5 is stalling pretty hard (which is fine), so our best bet will be to add this support directly into kraken I think.

from kraken-js.

dougwilson avatar dougwilson commented on May 27, 2024

Yea, and it should, but there are still unresolved issues on how exactly we should deal with the resolved values, for example, and how to deal with the Bluebird warnings, as another.

from kraken-js.

xjamundx avatar xjamundx commented on May 27, 2024

On the kraken side there a few ways to implement this. One place we may want to look at is in express-enrouten such as here:
https://github.com/krakenjs/express-enrouten/blob/v1.x/lib/directory.js#L69

from kraken-js.

xjamundx avatar xjamundx commented on May 27, 2024

Another thing we could do is put this monkey-patching script into its own module and just require it in as needed (either in kraken core or as wanted by various teams):
https://gist.github.com/q42jaap/f2fb93d96fda6384d3e3fc51977dec90

from kraken-js.

xjamundx avatar xjamundx commented on May 27, 2024

We could potentially integrate with this module:
https://github.com/davidbanham/express-async-errors

from kraken-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.