Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use in Express middleware #35

Open
FeelHippo opened this issue Apr 24, 2023 · 0 comments
Open

Use in Express middleware #35

FeelHippo opened this issue Apr 24, 2023 · 0 comments

Comments

@FeelHippo
Copy link

Hi there,

first off, thank you for this package, it's come in handy several times and always does a great job.
Documentation, however, could be expanded, and I have a question regarding its use in an ExpressJs middleware.

I would like to use "blocked" to investigate the cause of some timeouts we are experiencing in a controller.

I was wondering if I could do something like:

  • create a middleware like:
import { Request, Response, NextFunction } from 'express';
import * as blocked from 'blocked-at';

export default (_req: Request, _res: Response, next: NextFunction): void => {
  blocked(
    (time: any, stack: any) => {
      console.log(`Blocked for ${time}ms, operation started here:`, { stack });
    },
    { threshold: 1000 },
  );
  next();
};
  • and append this to our route handler
import { Router } from 'express';
import * as RestController from '.';
import ApiKeyAuth from '../../authorization/api-key-auth';
import blocked from '../../middleware/blocked';

router.post('/users', ApiKeyAuth, blocked, RestController.createUser);

I am testing this out with jMeter right now, and I have contrasting feelings on the effectiveness, what are your thoughts on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant