Middleware

This page summarizes the information & use of the middleware component.

Concepts

  • It is part of the Mandarine MVC module.

  • It works as an interceptor for HTTP requests made to a mandarine endpoint.

  • It accepts the use of DI, however, this type of component is not injectable.

Usage

Syntax:

@Middleware(regexRoute: RegExp)
  • regexRoute

    • Regular expression of HTTP endpoint url to intercept.

Example

import { Middleware, MiddlewareTarget } from "https://deno.land/x/mandarinets/mod.ts";

@Middleware(new RegExp('/api/*'))
export class Middleware1 implements MiddlewareTarget {

    // To be executed on pre-request of a request which url matches the middleware's regular expression route
    public onPreRequest(@ResponseParam() response: any): boolean {
        /**
         * True = the request must continue, 
         * False = the request will stop 
         */
        return true;
    }
    
    // To be executed on post-request of a request which url matches the middleware's regular expression route
    public onPostRequest(): void {
    }
}

Last updated