Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Use in Express middleware #35

Copy link
Copy link
@FeelHippo

Description

@FeelHippo
Issue body actions

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?

stathismor

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.