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