You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
import {AppClass} from '../../lifecycle/AppClass'
|
|
|
|
import {Request} from '../lifecycle/Request'
|
|
|
|
import {ResponseObject} from './Route'
|
|
|
|
import {Container} from '../../di'
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base class representing a middleware handler that can be applied to routes.
|
|
|
|
*/
|
|
|
|
export abstract class Middleware extends AppClass {
|
|
|
|
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<void>`, the request will continue to the
|
|
|
|
* next handler.
|
|
|
|
*/
|
|
|
|
public abstract apply(): ResponseObject
|
|
|
|
}
|