Skip to content

Commit 890b7c3

Browse files
committed
feat: add defineMiddleware and defineNamedMiddleware helpers
1 parent da8a24c commit 890b7c3

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ export { HttpException } from './src/exceptions/http_exception.js'
2222
export { AbortException } from './src/exceptions/abort_exception.js'
2323
export { RouteNotFoundException } from './src/exceptions/route_not_found.js'
2424
export { CannotLookupRouteException } from './src/exceptions/cannot_lookup_route.js'
25+
export { defineMiddleware, defineNamedMiddleware } from './src/define_middleware.js'

src/define_middleware.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* @adonisjs/http-server
3+
*
4+
* (c) AdonisJS
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
import type { LazyImport } from './types/base.js'
11+
import type { MiddlewareAsClass } from './types/middleware.js'
12+
13+
/**
14+
* Define an array of midldeware to be used either by the server
15+
* or the router
16+
*/
17+
export function defineMiddleware(list: LazyImport<MiddlewareAsClass>[]) {
18+
return list
19+
}
20+
21+
/**
22+
* Define an collection of named middleware. The name can be later be
23+
* referenced on the routes
24+
*/
25+
export function defineNamedMiddleware<
26+
NamedMiddleware extends Record<string, LazyImport<MiddlewareAsClass>>
27+
>(collection: NamedMiddleware) {
28+
return collection
29+
}

0 commit comments

Comments
 (0)