Mandarine.TS
Latest
Latest
  • Mandarine.TS
  • Getting started
    • Installing Deno Runtime
    • Setting up Environment
    • Quick Example
  • Concepts
  • Mandarine Project Structure
  • Mandarine CLI
    • CLI Reference
      • mandarine new
      • mandarine generate
      • mandarine run
  • Mandarine Core
    • Core Initialization
    • Mandarine.json
    • Dot env file
    • Properties
      • The @Value Decorator
    • Components
      • Controller
      • Middleware
      • Repository
      • Component
      • Service
      • Configuration
      • Manual Component
    • Dependency Injection
      • Accessing DI container
    • Resource Handlers
      • Resource Handler Registry
      • Resource Handler
      • Resource Resolver
  • Mandarine MVC
    • Web MVC
    • Controllers
      • Routes
        • Parameterized Routes
      • HTTP Handlers
      • @ResponseStatus
    • Custom Middleware
    • Session Middleware
    • CORS Middleware
    • Template Engine
      • @Render Decorator
      • Accessing data from template
    • Launching web-app
    • Serving Static Content
    • Multipart Form Data
  • Mandarine Security
    • Sessions
  • Mandarine Data
    • ORM
      • Data source
      • Models
      • Repositories
        • Interacting with data
        • Updating data
    • Mandarine Query Language
  • Resources
    • Changelog
  • Plugins
    • Optional
    • Promise Repeater
Powered by GitBook
On this page
  • Concepts
  • Usage

Was this helpful?

  1. Mandarine Core
  2. Components

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 {
    }
}

PreviousControllerNextRepository

Last updated 4 years ago

Was this helpful?