2021-06-03 03:36:25 +00:00
|
|
|
import {AppClass} from '../../lifecycle/AppClass'
|
|
|
|
import {Request} from '../lifecycle/Request'
|
|
|
|
import {ResponseObject} from './Route'
|
|
|
|
import {Container} from '../../di'
|
2021-03-09 15:42:19 +00:00
|
|
|
|
2021-03-25 13:50:13 +00:00
|
|
|
/**
|
|
|
|
* Base class representing a middleware handler that can be applied to routes.
|
|
|
|
*/
|
2021-03-09 15:42:19 +00:00
|
|
|
export abstract class Middleware extends AppClass {
|
|
|
|
constructor(
|
2021-03-25 13:50:13 +00:00
|
|
|
/** The request that will be handled by this middleware. */
|
2021-06-03 03:36:25 +00:00
|
|
|
protected readonly request: Request,
|
|
|
|
) {
|
|
|
|
super()
|
|
|
|
}
|
2021-03-09 15:42:19 +00:00
|
|
|
|
2021-06-03 03:36:25 +00:00
|
|
|
protected container(): Container {
|
2021-03-09 15:42:19 +00:00
|
|
|
return this.request
|
|
|
|
}
|
|
|
|
|
2021-03-25 13:50:13 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2021-03-09 15:42:19 +00:00
|
|
|
public abstract apply(): ResponseObject
|
|
|
|
}
|