GithubHelp home page GithubHelp logo

Middleware after response about tsoa HOT 7 CLOSED

SwagiWagi avatar SwagiWagi commented on June 13, 2024 1
Middleware after response

from tsoa.

Comments (7)

SwagiWagi avatar SwagiWagi commented on June 13, 2024 1

I believe an AfterMiddleware decorator would be a great feature.
It's great for use cases such as:

  1. Tracking the number of completed requests (for billing purposes for example).
  2. Logging.
  3. Disposing resources.

I believe it wouldn't be much work, I can make a PR for this.

from tsoa.

github-actions avatar github-actions commented on June 13, 2024

Hello there SwagiWagi 👋

Thank you for opening your very first issue in this project.

We will try to get back to you as soon as we can.👀

from tsoa.

jackey8616 avatar jackey8616 commented on June 13, 2024

I assume you are using Express,
there is two way to archive such feature.

  1. custom template and make your own handler function,
    register every route with after middleware by yourself,
    details you can search on StackOverflow, I believe there is some example such as Call middleware after response sent in Express
  2. tsoa indeed can provides such feature by including an AfterMiddleware decorator.
    but I doubt the necessity of it right now.

cc @WoH need your opinion.

from tsoa.

WoH avatar WoH commented on June 13, 2024
(req, res, next) => {

  next()

  console.log('post')
}

Should do it, right?

from tsoa.

jackey8616 avatar jackey8616 commented on June 13, 2024
(req, res, next) => {

  next()

  console.log('post')
}

Should do it, right?

try {
validatedArgs = templateService.getValidatedArgs({ args, request, response });
{{#if ../../iocModule}}
const container: IocContainer = typeof iocContainer === 'function' ? (iocContainer as IocContainerFactory)(request) : iocContainer;
const controller: any = await container.get<{{../name}}>({{../name}});
if (typeof controller['setStatus'] === 'function') {
controller.setStatus(undefined);
}
{{else}}
const controller = new {{../name}}();
{{/if}}
templateService.apiHandler({
methodName: '{{name}}',
controller,
response,
next,
validatedArgs,
successStatus: {{successStatus}},
});
} catch (err) {
return next(err);
}

Yes, just call next() in custom template, after L106 would work with after middleware.

from tsoa.

github-actions avatar github-actions commented on June 13, 2024

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

from tsoa.

ericwooley avatar ericwooley commented on June 13, 2024

Sorry to bring up a dead issue. But this doesn't appear to have been implemented.

I'm happy to do the PR if needed, or maybe there is discussion elsewhere as to why this wasn't added?

from tsoa.

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.