restyped-express-async icon indicating copy to clipboard operation
restyped-express-async copied to clipboard

Support for express middlewares

Open knordman opened this issue 6 years ago • 5 comments

So that one e.g. can write:

function firstMiddleware(req, res, next) {}
function secondMiddleware(req, res, next) {}

router.get(
    '/permissions',
    (req, res) => {
        return Promise.resolve().then(() => {
            return {
                managers: ['someone', 'another']
            };
        });
    },
    firstMiddleware, secondMiddleware
);

The router method call signature is backwards compatible but slightly unfortunately the middlewares need to be appended instead of prepended. Experimented with a single array of handlers but that did not turn out so well:

  • union objects in the array are not callable unless their call signature is identical https://github.com/Microsoft/TypeScript/issues/7294
  • if call signatures are identical, TypeScript won't differentiate the two on return value (since Handler has void), a faulty TypedHandler is hence interpreted as a Handler and no errors are generated

knordman avatar Sep 13 '18 04:09 knordman

Relates to #6

knordman avatar Sep 13 '18 04:09 knordman

This repo is still active ?

lbadi avatar Jan 21 '19 15:01 lbadi

:( I really like this project too...

evinism avatar Dec 07 '19 22:12 evinism

Hey, is this branch working? It's so unfortunate that this project isn't maintained anymore, I really like it too 😕

ianmartorell avatar Nov 13 '20 19:11 ianmartorell

I merged this branch in ianmartorell/restyped-express and published it to npm under restyped-express. I also fixed some other issues so it works with the latest version of express.

ianmartorell avatar Nov 14 '20 12:11 ianmartorell