Skip to content

Commit

Permalink
docs: Update documentation over overriding middlewares
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Sep 12, 2020
1 parent 161f91e commit 393ce9e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
7 changes: 0 additions & 7 deletions docs/docs/middlewares.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,6 @@ The decorator @@OverrideProvider@@ gives you the ability to override some intern

<<< @/docs/docs/snippets/middlewares/override-middleware.ts

Since v5.63.0, Ts.ED provide a PlatformResponseMiddleware (it replaces @@SendResponseMiddleware@@ and @@ResponseViewMiddleware@@),
to render a view and send the appropriate response to your consumer according to the executed endpoint.

You are able to override this middleware to change the initial behavior of this middleware.

<<< @/docs/docs/snippets/middlewares/override-platform-response-middleware.ts

Here we use the new [Platform API](/docs/platform-api.md) to write our middleware. By using @@Context@@ decorator and @@PlatformContext@@ class we can get some information:

- The data returned by the last executed endpoint,
Expand Down
9 changes: 7 additions & 2 deletions docs/docs/snippets/middlewares/override-middleware.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import {OriginalMiddleware, OverrideProvider} from "@tsed/common";
import {Context, OriginalMiddleware, OverrideProvider} from "@tsed/common";

@OverrideProvider(OriginalMiddleware)
export class CustomMiddleware extends OriginalMiddleware {
public use() {
public use(@Context() ctx: Context) {
ctx.response; // Ts.ED response
ctx.request; // Ts.ED resquest
ctx.getResponse(); // return Express.js or Koa.js response
ctx.getRequest(); // return Express.js or Koa.js request

// Do something
return super.use();
}
Expand Down

0 comments on commit 393ce9e

Please sign in to comment.