import {Request} from '../lifecycle/Request' import {ResponseObject} from './Route' import {Container} from '../../di' import {CanonicalItemClass} from '../../support/CanonicalReceiver' /** * Base class representing a middleware handler that can be applied to routes. */ export abstract class Middleware extends CanonicalItemClass { constructor( /** The request that will be handled by this middleware. */ protected readonly request: Request, ) { super() } protected container(): Container { return this.request } /** * Apply the middleware to the request. * If this returns a response factory or similar item, that will be sent * as a response. * * If this returns `void | Promise`, the request will continue to the * next handler. */ public abstract apply(): ResponseObject }