Global middleware

Global middlewares and Endpoint middlewares are almost similar but Global middleware cannot use the @EndpointInfo decorator. Global middlewares lets you manage request and response on ServerLoader.

Create your middleware:

import {IMiddleware, Middleware, Request, ServerSettingsService} from "@tsed/common";
import {NotAcceptable} from "ts-httpexceptions";

export default class GlobalAcceptMimesMiddleware implements IMiddleware {
   constructor(private serverSettingsService: ServerSettingsService) {


   use(@Request() request) {

            .forEach((mime) => {
                if (!request.accepts(mime)) {
                    throw new NotAcceptable(mime);

Then, add your middleware in ServerLoader:

   mount: {
      '/rest': `${rootDir}/controllers/**/**.js`
   componentsScan: [
   acceptMimes: ['application/json']  // add your custom configuration here
export class Server extends ServerLoader {
   $onMountingMiddlewares() {