Skip to content

Express Middlewares

Thiago Bustamante edited this page Mar 1, 2019 · 3 revisions

Express Middlewares

This library is an extension for expressjs. So, it is possible to use it together with other express middlewares. By default, after executing any service exposed with one of typescript-rest annotation, the library calls the express next function, that will call any other middleware registered in the express request pipeline.

If you want to disable this behaviour, you must use the @IgnoreNextMiddlewaresdecorator.

@Path('test')
class TestService {
   @GET
   @IgnoreNextMiddlewares
   test() {
       //...
      return new Return.RequestAccepted<void>(req.url + "/" + generatedId);
   }
}

To ignore next middlewares for all methods of a given class, it is possible to decorate the class itself.

@Path('test')
@IgnoreNextMiddlewares
class TestService {
   @GET
   test() {
       //...
      return new Return.RequestAccepted<void>(req.url + "/" + generatedId);
   }
}

If you want to ignore next middlewares for all services, it is possible to configure it directly through Server class:

Server.ignoreNextMiddlewares(true);

You can use the Context.next to call the next middlewares manually.