Skip to content

How to pass programatically generated req/res context to API controller functions? #9062

Discussion options

You must be logged in to vote

For posterity, I solved this via injecting the server to grab the sequence.

export class Module {
  constructor(
    @inject(RestBindings.SERVER)
    private serverCtx: Context,
    @inject(RestBindings.SERVER)
    private server: RestServer,
  ) { }

  async method() {
    ...
    const requestCtx = new RequestContext(req, res, this.serverCtx, this.server.config);
    const sequence = await requestCtx.get<SequenceHandler>(
      RestBindings.SEQUENCE,
    );
    await sequence.handle(requestCtx)
    ...
  }
}

Could have also grabbed the sequence directly via its binding key @inject(RestBindings.SEQUENCE) private sequence: MiddlewareSequence, but was seeing errors injecting it with my pa…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by flippingflapping
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant