Clean up middleware; solidify support for route handler classes

This commit is contained in:
2020-09-04 10:46:08 -05:00
parent ff34578d07
commit 27ee1a552b
5 changed files with 53 additions and 4 deletions

View File

@@ -1,5 +1,12 @@
import Middleware from '../../../lib/src/http/Middleware.ts'
import {Request} from '../../../lib/src/http/Request.ts'
import {http} from '../../../lib/src/http/response/helpers.ts'
import {HTTPStatus} from '../../../lib/src/const/http.ts'
export default class TestMiddleware extends Middleware {
public async handleRequest(request: Request) {
if ( Math.random() >= 0.5 ) {
return http(HTTPStatus.FORBIDDEN, 'Well, you were unlucky.')
}
}
}

View File

@@ -5,5 +5,6 @@ export default {
middleware: [],
get: {
'/': 'controller::Home.get_home',
'/maybe': ['middleware::Test', 'controller::Home.get_home'],
},
} as RouterDefinition