@adonisjs/http-server 6.8.2-6 → 6.8.2-8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -6
- package/build/factories/http_context.d.ts +10 -1
- package/build/factories/http_context.js +27 -0
- package/build/factories/http_server.d.ts +8 -0
- package/build/factories/http_server.js +26 -0
- package/build/factories/main.d.ts +0 -1
- package/build/factories/main.js +8 -0
- package/build/factories/qs_parser_factory.d.ts +10 -1
- package/build/factories/qs_parser_factory.js +18 -0
- package/build/factories/request.d.ts +10 -1
- package/build/factories/request.js +31 -0
- package/build/factories/response.d.ts +10 -1
- package/build/factories/response.js +34 -0
- package/build/factories/router.d.ts +10 -1
- package/build/factories/router.js +25 -0
- package/build/factories/server_factory.d.ts +10 -1
- package/build/factories/server_factory.js +34 -0
- package/build/index.d.ts +0 -1
- package/build/index.js +8 -0
- package/build/src/cookies/client.d.ts +25 -1
- package/build/src/cookies/client.js +42 -0
- package/build/src/cookies/drivers/encrypted.d.ts +12 -1
- package/build/src/cookies/drivers/encrypted.js +20 -0
- package/build/src/cookies/drivers/plain.d.ts +12 -1
- package/build/src/cookies/drivers/plain.js +20 -0
- package/build/src/cookies/drivers/signed.d.ts +12 -1
- package/build/src/cookies/drivers/signed.js +20 -0
- package/build/src/cookies/parser.d.ts +28 -1
- package/build/src/cookies/parser.js +98 -0
- package/build/src/cookies/serializer.d.ts +22 -1
- package/build/src/cookies/serializer.js +40 -0
- package/build/src/debug.d.ts +0 -1
- package/build/src/debug.js +8 -0
- package/build/src/define_config.d.ts +3 -1
- package/build/src/define_config.js +11 -0
- package/build/src/define_middleware.d.ts +5 -1
- package/build/src/define_middleware.js +18 -0
- package/build/src/exception_handler.d.ts +65 -1
- package/build/src/exception_handler.js +95 -0
- package/build/src/exceptions.d.ts +6 -1
- package/build/src/exceptions.js +11 -0
- package/build/src/helpers.d.ts +14 -1
- package/build/src/helpers.js +22 -0
- package/build/src/http_context/local_storage.d.ts +3 -1
- package/build/src/http_context/local_storage.js +25 -0
- package/build/src/http_context/main.d.ts +36 -1
- package/build/src/http_context/main.js +54 -0
- package/build/src/qs.d.ts +4 -1
- package/build/src/qs.js +12 -0
- package/build/src/redirect.d.ts +24 -1
- package/build/src/redirect.js +60 -0
- package/build/src/request.d.ts +466 -1
- package/build/src/request.js +542 -0
- package/build/src/response.d.ts +425 -2
- package/build/src/response.js +608 -7
- package/build/src/router/brisk.d.ts +22 -1
- package/build/src/router/brisk.js +42 -0
- package/build/src/router/executor.d.ts +4 -1
- package/build/src/router/executor.js +12 -0
- package/build/src/router/factories/use_return_value.d.ts +4 -1
- package/build/src/router/factories/use_return_value.js +16 -3
- package/build/src/router/group.d.ts +47 -1
- package/build/src/router/group.js +88 -0
- package/build/src/router/lookup_store/main.d.ts +32 -1
- package/build/src/router/lookup_store/main.js +49 -0
- package/build/src/router/lookup_store/route_finder.d.ts +13 -1
- package/build/src/router/lookup_store/route_finder.js +21 -0
- package/build/src/router/lookup_store/url_builder.d.ts +36 -1
- package/build/src/router/lookup_store/url_builder.js +97 -0
- package/build/src/router/main.d.ts +87 -1
- package/build/src/router/main.js +142 -0
- package/build/src/router/matchers.d.ts +13 -1
- package/build/src/router/matchers.js +21 -0
- package/build/src/router/parser.d.ts +3 -1
- package/build/src/router/parser.js +12 -0
- package/build/src/router/resource.d.ts +28 -1
- package/build/src/router/resource.js +90 -0
- package/build/src/router/route.d.ts +65 -1
- package/build/src/router/route.js +151 -2
- package/build/src/router/store.d.ts +54 -1
- package/build/src/router/store.js +107 -0
- package/build/src/server/factories/final_handler.d.ts +5 -1
- package/build/src/server/factories/final_handler.js +13 -0
- package/build/src/server/factories/middleware_handler.d.ts +3 -1
- package/build/src/server/factories/middleware_handler.js +11 -0
- package/build/src/server/factories/write_response.d.ts +4 -1
- package/build/src/server/factories/write_response.js +12 -0
- package/build/src/server/main.d.ts +48 -1
- package/build/src/server/main.js +128 -0
- package/build/src/types/base.d.ts +12 -1
- package/build/src/types/base.js +8 -0
- package/build/src/types/main.d.ts +0 -1
- package/build/src/types/main.js +8 -0
- package/build/src/types/middleware.d.ts +18 -1
- package/build/src/types/middleware.js +8 -0
- package/build/src/types/qs.d.ts +53 -1
- package/build/src/types/qs.js +8 -0
- package/build/src/types/request.d.ts +32 -1
- package/build/src/types/request.js +8 -0
- package/build/src/types/response.d.ts +27 -1
- package/build/src/types/response.js +8 -0
- package/build/src/types/route.d.ts +87 -1
- package/build/src/types/route.js +8 -0
- package/build/src/types/server.d.ts +35 -1
- package/build/src/types/server.js +8 -0
- package/package.json +44 -71
- package/build/factories/http_context.d.ts.map +0 -1
- package/build/factories/main.d.ts.map +0 -1
- package/build/factories/qs_parser_factory.d.ts.map +0 -1
- package/build/factories/request.d.ts.map +0 -1
- package/build/factories/response.d.ts.map +0 -1
- package/build/factories/router.d.ts.map +0 -1
- package/build/factories/server_factory.d.ts.map +0 -1
- package/build/index.d.ts.map +0 -1
- package/build/src/cookies/client.d.ts.map +0 -1
- package/build/src/cookies/drivers/encrypted.d.ts.map +0 -1
- package/build/src/cookies/drivers/plain.d.ts.map +0 -1
- package/build/src/cookies/drivers/signed.d.ts.map +0 -1
- package/build/src/cookies/parser.d.ts.map +0 -1
- package/build/src/cookies/serializer.d.ts.map +0 -1
- package/build/src/debug.d.ts.map +0 -1
- package/build/src/define_config.d.ts.map +0 -1
- package/build/src/define_middleware.d.ts.map +0 -1
- package/build/src/exception_handler.d.ts.map +0 -1
- package/build/src/exceptions.d.ts.map +0 -1
- package/build/src/helpers.d.ts.map +0 -1
- package/build/src/http_context/local_storage.d.ts.map +0 -1
- package/build/src/http_context/main.d.ts.map +0 -1
- package/build/src/qs.d.ts.map +0 -1
- package/build/src/redirect.d.ts.map +0 -1
- package/build/src/request.d.ts.map +0 -1
- package/build/src/response.d.ts.map +0 -1
- package/build/src/router/brisk.d.ts.map +0 -1
- package/build/src/router/executor.d.ts.map +0 -1
- package/build/src/router/factories/use_return_value.d.ts.map +0 -1
- package/build/src/router/group.d.ts.map +0 -1
- package/build/src/router/lookup_store/main.d.ts.map +0 -1
- package/build/src/router/lookup_store/route_finder.d.ts.map +0 -1
- package/build/src/router/lookup_store/url_builder.d.ts.map +0 -1
- package/build/src/router/main.d.ts.map +0 -1
- package/build/src/router/matchers.d.ts.map +0 -1
- package/build/src/router/parser.d.ts.map +0 -1
- package/build/src/router/resource.d.ts.map +0 -1
- package/build/src/router/route.d.ts.map +0 -1
- package/build/src/router/store.d.ts.map +0 -1
- package/build/src/server/factories/final_handler.d.ts.map +0 -1
- package/build/src/server/factories/middleware_handler.d.ts.map +0 -1
- package/build/src/server/factories/write_response.d.ts.map +0 -1
- package/build/src/server/main.d.ts.map +0 -1
- package/build/src/types/base.d.ts.map +0 -1
- package/build/src/types/main.d.ts.map +0 -1
- package/build/src/types/middleware.d.ts.map +0 -1
- package/build/src/types/qs.d.ts.map +0 -1
- package/build/src/types/request.d.ts.map +0 -1
- package/build/src/types/response.d.ts.map +0 -1
- package/build/src/types/route.d.ts.map +0 -1
- package/build/src/types/server.d.ts.map +0 -1
- package/factories/http_context.ts +0 -73
- package/factories/main.ts +0 -15
- package/factories/qs_parser_factory.ts +0 -54
- package/factories/request.ts +0 -101
- package/factories/response.ts +0 -106
- package/factories/router.ts +0 -61
- package/factories/server_factory.ts +0 -94
- package/index.ts +0 -23
- package/src/cookies/client.ts +0 -98
- package/src/cookies/drivers/encrypted.ts +0 -42
- package/src/cookies/drivers/plain.ts +0 -37
- package/src/cookies/drivers/signed.ts +0 -42
- package/src/cookies/parser.ts +0 -196
- package/src/cookies/serializer.ts +0 -98
- package/src/debug.ts +0 -11
- package/src/define_config.ts +0 -56
- package/src/define_middleware.ts +0 -61
- package/src/exception_handler.ts +0 -290
- package/src/exceptions.ts +0 -55
- package/src/helpers.ts +0 -108
- package/src/http_context/local_storage.ts +0 -50
- package/src/http_context/main.ts +0 -126
- package/src/qs.ts +0 -31
- package/src/redirect.ts +0 -181
- package/src/request.ts +0 -982
- package/src/response.ts +0 -1421
- package/src/router/brisk.ts +0 -113
- package/src/router/executor.ts +0 -36
- package/src/router/factories/use_return_value.ts +0 -26
- package/src/router/group.ts +0 -243
- package/src/router/lookup_store/main.ts +0 -102
- package/src/router/lookup_store/route_finder.ts +0 -60
- package/src/router/lookup_store/url_builder.ts +0 -250
- package/src/router/main.ts +0 -431
- package/src/router/matchers.ts +0 -40
- package/src/router/parser.ts +0 -20
- package/src/router/resource.ts +0 -277
- package/src/router/route.ts +0 -363
- package/src/router/store.ts +0 -239
- package/src/server/factories/final_handler.ts +0 -38
- package/src/server/factories/middleware_handler.ts +0 -23
- package/src/server/factories/write_response.ts +0 -26
- package/src/server/main.ts +0 -356
- package/src/types/base.ts +0 -30
- package/src/types/main.ts +0 -16
- package/src/types/middleware.ts +0 -59
- package/src/types/qs.ts +0 -85
- package/src/types/request.ts +0 -52
- package/src/types/response.ts +0 -57
- package/src/types/route.ts +0 -217
- package/src/types/server.ts +0 -92
package/src/router/brisk.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
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 Macroable from '@poppinss/macroable'
|
|
11
|
-
import type { Application } from '@adonisjs/application'
|
|
12
|
-
|
|
13
|
-
import { Route } from './route.js'
|
|
14
|
-
import type { ParsedGlobalMiddleware } from '../types/middleware.js'
|
|
15
|
-
import type { MakeUrlOptions, RouteFn, RouteMatchers } from '../types/route.js'
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Brisk routes exposes the API to configure the route handler by chaining
|
|
19
|
-
* one of the pre-defined methods.
|
|
20
|
-
*
|
|
21
|
-
* For example: Instead of defining the redirect logic as a callback, one can
|
|
22
|
-
* chain the `.redirect` method.
|
|
23
|
-
*
|
|
24
|
-
* Brisk routes are always registered under the `GET` HTTP method.
|
|
25
|
-
*/
|
|
26
|
-
export class BriskRoute extends Macroable {
|
|
27
|
-
/**
|
|
28
|
-
* Route pattern
|
|
29
|
-
*/
|
|
30
|
-
#pattern: string
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Matchers inherited from the router
|
|
34
|
-
*/
|
|
35
|
-
#globalMatchers: RouteMatchers
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Reference to the AdonisJS application
|
|
39
|
-
*/
|
|
40
|
-
#app: Application<any>
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Middleware registered on the router
|
|
44
|
-
*/
|
|
45
|
-
#routerMiddleware: ParsedGlobalMiddleware[]
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Reference to route instance. Set after `setHandler` is called
|
|
49
|
-
*/
|
|
50
|
-
route: null | Route = null
|
|
51
|
-
|
|
52
|
-
constructor(
|
|
53
|
-
app: Application<any>,
|
|
54
|
-
routerMiddleware: ParsedGlobalMiddleware[],
|
|
55
|
-
options: {
|
|
56
|
-
pattern: string
|
|
57
|
-
globalMatchers: RouteMatchers
|
|
58
|
-
}
|
|
59
|
-
) {
|
|
60
|
-
super()
|
|
61
|
-
this.#app = app
|
|
62
|
-
this.#routerMiddleware = routerMiddleware
|
|
63
|
-
this.#pattern = options.pattern
|
|
64
|
-
this.#globalMatchers = options.globalMatchers
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Set handler for the brisk route
|
|
69
|
-
*/
|
|
70
|
-
setHandler(handler: RouteFn): Route {
|
|
71
|
-
this.route = new Route(this.#app, this.#routerMiddleware, {
|
|
72
|
-
pattern: this.#pattern,
|
|
73
|
-
globalMatchers: this.#globalMatchers,
|
|
74
|
-
methods: ['GET', 'HEAD'],
|
|
75
|
-
handler: handler,
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
return this.route
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Redirects to a given route. Params from the original request will
|
|
83
|
-
* be used when no custom params are defined.
|
|
84
|
-
*/
|
|
85
|
-
redirect(
|
|
86
|
-
identifier: string,
|
|
87
|
-
params?: any[] | Record<string, any>,
|
|
88
|
-
options?: MakeUrlOptions & { status: number }
|
|
89
|
-
): Route {
|
|
90
|
-
return this.setHandler(async function redirectsToRoute(ctx) {
|
|
91
|
-
const redirector = ctx.response.redirect()
|
|
92
|
-
if (options?.status) {
|
|
93
|
-
redirector.status(options.status)
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return redirector.toRoute(identifier, params || ctx.params, options)
|
|
97
|
-
})
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Redirect request to a fixed URL
|
|
102
|
-
*/
|
|
103
|
-
redirectToPath(url: string, options?: { status: number }): Route {
|
|
104
|
-
return this.setHandler(async function redirectsToPath(ctx) {
|
|
105
|
-
const redirector = ctx.response.redirect()
|
|
106
|
-
if (options?.status) {
|
|
107
|
-
redirector.status(options.status)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return redirector.toPath(url)
|
|
111
|
-
})
|
|
112
|
-
}
|
|
113
|
-
}
|
package/src/router/executor.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
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 { ContainerResolver } from '@adonisjs/fold'
|
|
11
|
-
import type { StoreRouteNode } from '../types/route.js'
|
|
12
|
-
import type { HttpContext } from '../http_context/main.js'
|
|
13
|
-
import { useReturnValue } from './factories/use_return_value.js'
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Executor to execute the route middleware pipeline the route
|
|
17
|
-
* handler
|
|
18
|
-
*/
|
|
19
|
-
export function execute(route: StoreRouteNode, resolver: ContainerResolver<any>, ctx: HttpContext) {
|
|
20
|
-
return route.middleware
|
|
21
|
-
.runner()
|
|
22
|
-
.finalHandler(async () => {
|
|
23
|
-
if (typeof route.handler === 'function') {
|
|
24
|
-
return Promise.resolve(route.handler(ctx)).then(useReturnValue(ctx))
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return route.handler.handle(resolver, ctx).then(useReturnValue(ctx))
|
|
28
|
-
})
|
|
29
|
-
.run(async (middleware, next) => {
|
|
30
|
-
if (typeof middleware === 'function') {
|
|
31
|
-
return middleware(ctx, next)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return middleware.handle(resolver, ctx, next, middleware.args)
|
|
35
|
-
})
|
|
36
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
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 { HttpContext } from '../../http_context/main.js'
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* A factory function that uses the return value of the request
|
|
14
|
-
* pipeline as the response
|
|
15
|
-
*/
|
|
16
|
-
export function useReturnValue(ctx: HttpContext) {
|
|
17
|
-
return function (value: any) {
|
|
18
|
-
if (
|
|
19
|
-
value !== undefined && // Return value is explicitly defined
|
|
20
|
-
!ctx.response.hasLazyBody && // Lazy body is not set
|
|
21
|
-
value !== ctx.response // Return value is not the instance of response object
|
|
22
|
-
) {
|
|
23
|
-
ctx.response.send(value)
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
package/src/router/group.ts
DELETED
|
@@ -1,243 +0,0 @@
|
|
|
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 Macroable from '@poppinss/macroable'
|
|
11
|
-
import type { RouteMatcher, StoreRouteMiddleware } from '../types/route.js'
|
|
12
|
-
import type { MiddlewareFn, ParsedNamedMiddleware } from '../types/middleware.js'
|
|
13
|
-
|
|
14
|
-
import { Route } from './route.js'
|
|
15
|
-
import { BriskRoute } from './brisk.js'
|
|
16
|
-
import { RouteResource } from './resource.js'
|
|
17
|
-
import { OneOrMore } from '../types/base.js'
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Group class exposes the API to take action on a group of routes.
|
|
21
|
-
* The group routes must be pre-defined using the constructor.
|
|
22
|
-
*/
|
|
23
|
-
export class RouteGroup extends Macroable {
|
|
24
|
-
/**
|
|
25
|
-
* Array of middleware registered on the group.
|
|
26
|
-
*/
|
|
27
|
-
#middleware: StoreRouteMiddleware[] = []
|
|
28
|
-
|
|
29
|
-
constructor(public routes: (Route | RouteGroup | RouteResource | BriskRoute)[]) {
|
|
30
|
-
super()
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Shares midldeware stack with the routes. The method is invoked recursively
|
|
35
|
-
* to only register middleware with the route class and not with the
|
|
36
|
-
* resource or the child group
|
|
37
|
-
*/
|
|
38
|
-
#shareMiddlewareStackWithRoutes(route: RouteGroup | Route | RouteResource | BriskRoute) {
|
|
39
|
-
if (route instanceof RouteGroup) {
|
|
40
|
-
route.routes.forEach((child) => this.#shareMiddlewareStackWithRoutes(child))
|
|
41
|
-
return
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (route instanceof RouteResource) {
|
|
45
|
-
route.routes.forEach((child) => child.getMiddleware().unshift(this.#middleware))
|
|
46
|
-
return
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (route instanceof BriskRoute) {
|
|
50
|
-
route.route!.getMiddleware().unshift(this.#middleware)
|
|
51
|
-
return
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
route.getMiddleware().unshift(this.#middleware)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Updates the route name. The method is invoked recursively to only update
|
|
59
|
-
* the name with the route class and not with the resource or the child
|
|
60
|
-
* group.
|
|
61
|
-
*/
|
|
62
|
-
#updateRouteName(route: RouteGroup | Route | RouteResource | BriskRoute, name: string) {
|
|
63
|
-
if (route instanceof RouteGroup) {
|
|
64
|
-
route.routes.forEach((child) => this.#updateRouteName(child, name))
|
|
65
|
-
return
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (route instanceof RouteResource) {
|
|
69
|
-
route.routes.forEach((child) => child.as(name, true))
|
|
70
|
-
return
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (route instanceof BriskRoute) {
|
|
74
|
-
route.route!.as(name, true)
|
|
75
|
-
return
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
route.as(name, true)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Sets prefix on the route. The method is invoked recursively to only set
|
|
83
|
-
* the prefix with the route class and not with the resource or the
|
|
84
|
-
* child group.
|
|
85
|
-
*/
|
|
86
|
-
#setRoutePrefix(route: RouteGroup | Route | RouteResource | BriskRoute, prefix: string) {
|
|
87
|
-
if (route instanceof RouteGroup) {
|
|
88
|
-
route.routes.forEach((child) => this.#setRoutePrefix(child, prefix))
|
|
89
|
-
return
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (route instanceof RouteResource) {
|
|
93
|
-
route.routes.forEach((child) => child.prefix(prefix))
|
|
94
|
-
return
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (route instanceof BriskRoute) {
|
|
98
|
-
route.route!.prefix(prefix)
|
|
99
|
-
return
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
route.prefix(prefix)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Updates domain on the route. The method is invoked recursively to only update
|
|
107
|
-
* the domain with the route class and not with the resource or the child
|
|
108
|
-
* group.
|
|
109
|
-
*/
|
|
110
|
-
#updateRouteDomain(route: RouteGroup | Route | RouteResource | BriskRoute, domain: string) {
|
|
111
|
-
if (route instanceof RouteGroup) {
|
|
112
|
-
route.routes.forEach((child) => this.#updateRouteDomain(child, domain))
|
|
113
|
-
return
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (route instanceof RouteResource) {
|
|
117
|
-
route.routes.forEach((child) => child.domain(domain))
|
|
118
|
-
return
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (route instanceof BriskRoute) {
|
|
122
|
-
route.route!.domain(domain, false)
|
|
123
|
-
return
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
route.domain(domain, false)
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Updates matchers on the route. The method is invoked recursively to only update
|
|
131
|
-
* the matchers with the route class and not with the resource or the child
|
|
132
|
-
* group.
|
|
133
|
-
*/
|
|
134
|
-
#updateRouteMatchers(
|
|
135
|
-
route: RouteGroup | Route | RouteResource | BriskRoute,
|
|
136
|
-
param: string,
|
|
137
|
-
matcher: RouteMatcher | string | RegExp
|
|
138
|
-
) {
|
|
139
|
-
if (route instanceof RouteGroup) {
|
|
140
|
-
route.routes.forEach((child) => this.#updateRouteMatchers(child, param, matcher))
|
|
141
|
-
return
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if (route instanceof RouteResource) {
|
|
145
|
-
route.routes.forEach((child) => child.where(param, matcher))
|
|
146
|
-
return
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (route instanceof BriskRoute) {
|
|
150
|
-
route.route!.where(param, matcher)
|
|
151
|
-
return
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
route.where(param, matcher)
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Define route param matcher
|
|
159
|
-
*
|
|
160
|
-
* ```ts
|
|
161
|
-
* Route.group(() => {
|
|
162
|
-
* }).where('id', /^[0-9]+/)
|
|
163
|
-
* ```
|
|
164
|
-
*/
|
|
165
|
-
where(param: string, matcher: RouteMatcher | string | RegExp): this {
|
|
166
|
-
this.routes.forEach((route) => this.#updateRouteMatchers(route, param, matcher))
|
|
167
|
-
return this
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Define prefix all the routes in the group.
|
|
172
|
-
*
|
|
173
|
-
* ```ts
|
|
174
|
-
* Route.group(() => {
|
|
175
|
-
* }).prefix('v1')
|
|
176
|
-
* ```
|
|
177
|
-
*/
|
|
178
|
-
prefix(prefix: string): this {
|
|
179
|
-
this.routes.forEach((route) => this.#setRoutePrefix(route, prefix))
|
|
180
|
-
return this
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Define domain for all the routes.
|
|
185
|
-
*
|
|
186
|
-
* ```ts
|
|
187
|
-
* Route.group(() => {
|
|
188
|
-
* }).domain(':name.adonisjs.com')
|
|
189
|
-
* ```
|
|
190
|
-
*/
|
|
191
|
-
domain(domain: string): this {
|
|
192
|
-
this.routes.forEach((route) => this.#updateRouteDomain(route, domain))
|
|
193
|
-
return this
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Prepend name to the routes name.
|
|
198
|
-
*
|
|
199
|
-
* ```ts
|
|
200
|
-
* Route.group(() => {
|
|
201
|
-
* }).as('version1')
|
|
202
|
-
* ```
|
|
203
|
-
*/
|
|
204
|
-
as(name: string): this {
|
|
205
|
-
this.routes.forEach((route) => this.#updateRouteName(route, name))
|
|
206
|
-
return this
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Prepend an array of middleware to all routes middleware.
|
|
210
|
-
*
|
|
211
|
-
* ```ts
|
|
212
|
-
* Route.group(() => {
|
|
213
|
-
* }).use(middleware.auth())
|
|
214
|
-
* ```
|
|
215
|
-
*/
|
|
216
|
-
use(middleware: OneOrMore<MiddlewareFn | ParsedNamedMiddleware>): this {
|
|
217
|
-
/**
|
|
218
|
-
* Register middleware with children. We share the group middleware
|
|
219
|
-
* array by reference, therefore have to register it only for the
|
|
220
|
-
* first time.
|
|
221
|
-
*/
|
|
222
|
-
if (!this.#middleware.length) {
|
|
223
|
-
this.routes.forEach((route) => this.#shareMiddlewareStackWithRoutes(route))
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
if (Array.isArray(middleware)) {
|
|
227
|
-
for (let one of middleware) {
|
|
228
|
-
this.#middleware.push(one)
|
|
229
|
-
}
|
|
230
|
-
} else {
|
|
231
|
-
this.#middleware.push(middleware)
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
return this
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* @alias use
|
|
239
|
-
*/
|
|
240
|
-
middleware(middleware: OneOrMore<MiddlewareFn | ParsedNamedMiddleware>): this {
|
|
241
|
-
return this.use(middleware)
|
|
242
|
-
}
|
|
243
|
-
}
|
|
@@ -1,102 +0,0 @@
|
|
|
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 { Encryption } from '@adonisjs/encryption'
|
|
11
|
-
|
|
12
|
-
import type { Qs } from '../../qs.js'
|
|
13
|
-
import { UrlBuilder } from './url_builder.js'
|
|
14
|
-
import { RouteFinder } from './route_finder.js'
|
|
15
|
-
import type { RouteJSON } from '../../types/route.js'
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Lookup store exposes the API to lookup routes and
|
|
19
|
-
* make URLs for registered routes.
|
|
20
|
-
*/
|
|
21
|
-
export class LookupStore {
|
|
22
|
-
/**
|
|
23
|
-
* List of routes grouped by domain
|
|
24
|
-
*/
|
|
25
|
-
#routes: { [domain: string]: RouteJSON[] } = {}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Encryption for making URLs
|
|
29
|
-
*/
|
|
30
|
-
#encryption: Encryption
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Query string parser for making URLs
|
|
34
|
-
*/
|
|
35
|
-
#qsParser: Qs
|
|
36
|
-
|
|
37
|
-
constructor(encryption: Encryption, qsParser: Qs) {
|
|
38
|
-
this.#encryption = encryption
|
|
39
|
-
this.#qsParser = qsParser
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Register route JSON payload
|
|
44
|
-
*/
|
|
45
|
-
register(route: RouteJSON) {
|
|
46
|
-
this.#routes[route.domain] = this.#routes[route.domain] || []
|
|
47
|
-
this.#routes[route.domain].push(route)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Returns an instance of the URL builder for making
|
|
52
|
-
* route URIs
|
|
53
|
-
*/
|
|
54
|
-
builder() {
|
|
55
|
-
return this.builderForDomain('root')
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Returns an instance of the URL builder for a specific
|
|
60
|
-
* domain.
|
|
61
|
-
*/
|
|
62
|
-
builderForDomain(domain: string) {
|
|
63
|
-
const routes = this.#routes[domain]
|
|
64
|
-
return new UrlBuilder(this.#encryption, new RouteFinder(routes || []), this.#qsParser)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Finds a route by its identifier. The identifier can be the
|
|
69
|
-
* route name, controller.method name or the route pattern
|
|
70
|
-
* itself.
|
|
71
|
-
*/
|
|
72
|
-
find(routeIdentifier: string, domain?: string): RouteJSON | null {
|
|
73
|
-
const routes = this.#routes[domain || 'root'] || []
|
|
74
|
-
return new RouteFinder(routes).find(routeIdentifier)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Finds a route by its identifier. The identifier can be the
|
|
79
|
-
* route name, controller.method name or the route pattern
|
|
80
|
-
* itself.
|
|
81
|
-
*
|
|
82
|
-
* An error is raised when unable to find the route.
|
|
83
|
-
*/
|
|
84
|
-
findOrFail(routeIdentifier: string, domain?: string): RouteJSON {
|
|
85
|
-
const routes = this.#routes[domain || 'root'] || []
|
|
86
|
-
return new RouteFinder(routes).findOrFail(routeIdentifier)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Check if a route exists. The identifier can be the
|
|
91
|
-
* route name, controller.method name or the route pattern
|
|
92
|
-
* itself.
|
|
93
|
-
*/
|
|
94
|
-
has(routeIdentifier: string, domain?: string): boolean {
|
|
95
|
-
const routes = this.#routes[domain || 'root'] || []
|
|
96
|
-
return new RouteFinder(routes).has(routeIdentifier)
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
toJSON() {
|
|
100
|
-
return this.#routes
|
|
101
|
-
}
|
|
102
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
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 * as errors from '../../exceptions.js'
|
|
11
|
-
import type { RouteJSON } from '../../types/route.js'
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Route finder is used to find a route by its name, route pattern
|
|
15
|
-
* or the controller.method name.
|
|
16
|
-
*/
|
|
17
|
-
export class RouteFinder {
|
|
18
|
-
#routes: RouteJSON[]
|
|
19
|
-
constructor(routes: RouteJSON[]) {
|
|
20
|
-
this.#routes = routes
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Find a route by indentifier
|
|
25
|
-
*/
|
|
26
|
-
find(routeIdentifier: string): RouteJSON | null {
|
|
27
|
-
return (
|
|
28
|
-
this.#routes.find(({ name, pattern, handler }) => {
|
|
29
|
-
if (name === routeIdentifier || pattern === routeIdentifier) {
|
|
30
|
-
return true
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (typeof handler === 'function') {
|
|
34
|
-
return false
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return handler.reference === routeIdentifier
|
|
38
|
-
}) || null
|
|
39
|
-
)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Find a route by indentifier or fail
|
|
44
|
-
*/
|
|
45
|
-
findOrFail(routeIdentifier: string): RouteJSON {
|
|
46
|
-
const route = this.find(routeIdentifier)
|
|
47
|
-
if (!route) {
|
|
48
|
-
throw new errors.E_CANNOT_LOOKUP_ROUTE([routeIdentifier])
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return route
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Find if a route exists
|
|
56
|
-
*/
|
|
57
|
-
has(routeIdentifier: string): boolean {
|
|
58
|
-
return !!this.find(routeIdentifier)
|
|
59
|
-
}
|
|
60
|
-
}
|