Skip to content

Commit

Permalink
feat(rest): expose RequestContext to Express request object
Browse files Browse the repository at this point in the history
This is needed for GraphQL integration as a REST middleware to access
the RequestContext for Dependency Injection.

Signed-off-by: Raymond Feng <[email protected]>
  • Loading branch information
raymondfeng committed Sep 3, 2020
1 parent c61e492 commit 3024f5d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/rest/src/http-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// License text available at https://opensource.org/licenses/MIT

import {Context} from '@loopback/core';
import {MIDDLEWARE_CONTEXT} from '@loopback/express';
import {
ComponentsObject,
ControllerSpec,
Expand Down Expand Up @@ -109,6 +110,11 @@ export class HttpHandler {
this._serverConfig,
);

// Set the request context as a property of Express request object so that
// downstream Express native integration can access `RequestContext`
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(request as any)[MIDDLEWARE_CONTEXT] = requestContext;

const sequence = await requestContext.get<SequenceHandler>(
RestBindings.SEQUENCE,
);
Expand Down

0 comments on commit 3024f5d

Please sign in to comment.