@adonisjs/http-server 5.11.0 → 6.0.0-0

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.
Files changed (169) hide show
  1. package/README.md +15 -38
  2. package/build/index.d.ts +16 -0
  3. package/build/index.js +16 -0
  4. package/build/src/cookies/client.d.ts +12 -0
  5. package/build/src/cookies/client.js +42 -0
  6. package/build/src/cookies/drivers/encrypted.d.ts +4 -0
  7. package/build/src/cookies/drivers/encrypted.js +16 -0
  8. package/build/src/cookies/drivers/plain.d.ts +3 -0
  9. package/build/src/cookies/drivers/plain.js +13 -0
  10. package/build/src/cookies/drivers/signed.d.ts +4 -0
  11. package/build/src/cookies/drivers/signed.js +16 -0
  12. package/build/src/cookies/parser.d.ts +9 -0
  13. package/build/src/cookies/parser.js +69 -0
  14. package/build/src/cookies/serializer.d.ts +11 -0
  15. package/build/src/cookies/serializer.js +39 -0
  16. package/build/src/debug.d.ts +3 -0
  17. package/build/src/debug.js +2 -0
  18. package/build/src/define_config.d.ts +2 -0
  19. package/build/src/define_config.js +40 -0
  20. package/build/src/define_middleware.d.ts +4 -0
  21. package/build/src/define_middleware.js +6 -0
  22. package/build/src/exceptions/abort_exception.d.ts +5 -0
  23. package/build/src/exceptions/abort_exception.js +6 -0
  24. package/build/src/exceptions/cannot_lookup_route.d.ts +5 -0
  25. package/build/src/exceptions/cannot_lookup_route.js +5 -0
  26. package/build/src/exceptions/http_exception.d.ts +6 -0
  27. package/build/src/exceptions/http_exception.js +20 -0
  28. package/build/src/exceptions/route_not_found.d.ts +5 -0
  29. package/build/src/exceptions/route_not_found.js +5 -0
  30. package/build/src/helpers.d.ts +6 -67
  31. package/build/src/helpers.js +13 -168
  32. package/build/src/http_context/local_storage.d.ts +9 -0
  33. package/build/src/http_context/local_storage.js +14 -0
  34. package/build/src/http_context/main.d.ts +20 -0
  35. package/build/src/http_context/main.js +49 -0
  36. package/build/src/middleware/store.d.ts +11 -0
  37. package/build/src/middleware/store.js +33 -0
  38. package/build/src/qs.d.ts +7 -0
  39. package/build/src/qs.js +13 -0
  40. package/build/src/redirect.d.ts +18 -0
  41. package/build/src/redirect.js +80 -0
  42. package/build/src/request.d.ts +81 -0
  43. package/build/src/request.js +315 -0
  44. package/build/src/response.d.ts +108 -0
  45. package/build/src/response.js +587 -0
  46. package/build/src/router/brisk.d.ts +18 -0
  47. package/build/src/router/brisk.js +35 -0
  48. package/build/src/router/executor.d.ts +4 -0
  49. package/build/src/router/executor.js +16 -0
  50. package/build/src/router/group.d.ts +19 -0
  51. package/build/src/router/group.js +117 -0
  52. package/build/src/router/lookup_store/main.d.ts +17 -0
  53. package/build/src/router/lookup_store/main.js +37 -0
  54. package/build/src/router/lookup_store/route_finder.d.ts +8 -0
  55. package/build/src/router/lookup_store/route_finder.js +28 -0
  56. package/build/src/router/lookup_store/url_builder.d.ts +16 -0
  57. package/build/src/router/lookup_store/url_builder.js +111 -0
  58. package/build/src/router/main.d.ts +36 -0
  59. package/build/src/router/main.js +161 -0
  60. package/build/src/router/matchers.d.ts +14 -0
  61. package/build/src/router/matchers.js +15 -0
  62. package/build/src/router/resource.d.ts +27 -0
  63. package/build/src/router/resource.js +124 -0
  64. package/build/src/router/route.d.ts +28 -0
  65. package/build/src/router/route.js +135 -0
  66. package/build/src/router/store.d.ts +12 -0
  67. package/build/src/router/store.js +87 -0
  68. package/build/src/server/factories/final_handler.d.ts +4 -0
  69. package/build/src/server/factories/final_handler.js +17 -0
  70. package/build/src/server/factories/middleware_handler.d.ts +5 -0
  71. package/build/src/server/factories/middleware_handler.js +5 -0
  72. package/build/src/server/factories/use_return_value.d.ts +2 -0
  73. package/build/src/server/factories/use_return_value.js +9 -0
  74. package/build/src/server/factories/write_response.d.ts +2 -0
  75. package/build/src/server/factories/write_response.js +12 -0
  76. package/build/src/server/main.d.ts +23 -0
  77. package/build/src/server/main.js +124 -0
  78. package/build/src/types/base.d.ts +5 -0
  79. package/build/src/types/base.js +1 -0
  80. package/build/src/types/middleware.d.ts +14 -0
  81. package/build/src/types/middleware.js +1 -0
  82. package/build/src/types/qs.d.ts +15 -0
  83. package/build/src/types/qs.js +1 -0
  84. package/build/src/types/request.d.ts +7 -0
  85. package/build/src/types/request.js +1 -0
  86. package/build/src/types/response.d.ts +18 -0
  87. package/build/src/types/response.js +1 -0
  88. package/build/src/types/route.d.ts +74 -0
  89. package/build/src/types/route.js +1 -0
  90. package/build/src/types/server.d.ts +13 -0
  91. package/build/src/types/server.js +1 -0
  92. package/package.json +98 -96
  93. package/build/adonis-typings/container.d.ts +0 -24
  94. package/build/adonis-typings/container.js +0 -8
  95. package/build/adonis-typings/context.d.ts +0 -73
  96. package/build/adonis-typings/context.js +0 -8
  97. package/build/adonis-typings/cookie-client.d.ts +0 -34
  98. package/build/adonis-typings/cookie-client.js +0 -8
  99. package/build/adonis-typings/http-server.d.ts +0 -98
  100. package/build/adonis-typings/http-server.js +0 -8
  101. package/build/adonis-typings/index.d.ts +0 -16
  102. package/build/adonis-typings/index.js +0 -16
  103. package/build/adonis-typings/middleware.d.ts +0 -95
  104. package/build/adonis-typings/middleware.js +0 -8
  105. package/build/adonis-typings/request.d.ts +0 -556
  106. package/build/adonis-typings/request.js +0 -8
  107. package/build/adonis-typings/response.d.ts +0 -438
  108. package/build/adonis-typings/response.js +0 -8
  109. package/build/adonis-typings/route.d.ts +0 -559
  110. package/build/adonis-typings/route.js +0 -8
  111. package/build/exceptions.json +0 -110
  112. package/build/providers/HttpServerProvider.d.ts +0 -46
  113. package/build/providers/HttpServerProvider.js +0 -100
  114. package/build/src/Cookie/Client/index.d.ts +0 -39
  115. package/build/src/Cookie/Client/index.js +0 -108
  116. package/build/src/Cookie/Drivers/Encrypted.d.ts +0 -24
  117. package/build/src/Cookie/Drivers/Encrypted.js +0 -42
  118. package/build/src/Cookie/Drivers/Plain.d.ts +0 -23
  119. package/build/src/Cookie/Drivers/Plain.js +0 -40
  120. package/build/src/Cookie/Drivers/Signed.d.ts +0 -24
  121. package/build/src/Cookie/Drivers/Signed.js +0 -42
  122. package/build/src/Cookie/Parser/index.d.ts +0 -61
  123. package/build/src/Cookie/Parser/index.js +0 -174
  124. package/build/src/Cookie/Serializer/index.d.ts +0 -44
  125. package/build/src/Cookie/Serializer/index.js +0 -88
  126. package/build/src/Exceptions/HttpException.d.ts +0 -20
  127. package/build/src/Exceptions/HttpException.js +0 -36
  128. package/build/src/Exceptions/RouterException.d.ts +0 -36
  129. package/build/src/Exceptions/RouterException.js +0 -76
  130. package/build/src/HttpContext/LocalStorage/index.d.ts +0 -24
  131. package/build/src/HttpContext/LocalStorage/index.js +0 -28
  132. package/build/src/HttpContext/index.d.ts +0 -90
  133. package/build/src/HttpContext/index.js +0 -181
  134. package/build/src/MiddlewareStore/index.d.ts +0 -92
  135. package/build/src/MiddlewareStore/index.js +0 -133
  136. package/build/src/Redirect/index.d.ts +0 -71
  137. package/build/src/Redirect/index.js +0 -139
  138. package/build/src/Request/index.d.ts +0 -619
  139. package/build/src/Request/index.js +0 -862
  140. package/build/src/Response/index.d.ts +0 -412
  141. package/build/src/Response/index.js +0 -1010
  142. package/build/src/Router/BriskRoute.d.ts +0 -53
  143. package/build/src/Router/BriskRoute.js +0 -74
  144. package/build/src/Router/Group.d.ts +0 -101
  145. package/build/src/Router/Group.js +0 -165
  146. package/build/src/Router/LookupStore.d.ts +0 -122
  147. package/build/src/Router/LookupStore.js +0 -264
  148. package/build/src/Router/Matchers.d.ts +0 -31
  149. package/build/src/Router/Matchers.js +0 -43
  150. package/build/src/Router/Resource.d.ts +0 -95
  151. package/build/src/Router/Resource.js +0 -182
  152. package/build/src/Router/Route.d.ts +0 -138
  153. package/build/src/Router/Route.js +0 -204
  154. package/build/src/Router/Store.d.ts +0 -93
  155. package/build/src/Router/Store.js +0 -211
  156. package/build/src/Router/index.d.ts +0 -142
  157. package/build/src/Router/index.js +0 -333
  158. package/build/src/Server/ExceptionManager/index.d.ts +0 -49
  159. package/build/src/Server/ExceptionManager/index.js +0 -96
  160. package/build/src/Server/Hooks/index.d.ts +0 -43
  161. package/build/src/Server/Hooks/index.js +0 -77
  162. package/build/src/Server/PreCompiler/index.d.ts +0 -60
  163. package/build/src/Server/PreCompiler/index.js +0 -141
  164. package/build/src/Server/RequestHandler/index.d.ts +0 -39
  165. package/build/src/Server/RequestHandler/index.js +0 -87
  166. package/build/src/Server/index.d.ts +0 -90
  167. package/build/src/Server/index.js +0 -175
  168. package/build/standalone.d.ts +0 -14
  169. package/build/standalone.js +0 -23
@@ -1,142 +0,0 @@
1
- /**
2
- * @adonisjs/http-server
3
- *
4
- * (c) Harminder Virk <virk@adonisjs.com>
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- /// <reference path="../../adonis-typings/index.d.ts" />
10
- import { EncryptionContract } from '@ioc:Adonis/Core/Encryption';
11
- import { RouteNode, RouteHandler, MatchedRoute, RouterContract, MakeUrlOptions, MakeSignedUrlOptions } from '@ioc:Adonis/Core/Route';
12
- import { Route } from './Route';
13
- import { RouteGroup } from './Group';
14
- import { BriskRoute } from './BriskRoute';
15
- import { RouteResource } from './Resource';
16
- import { RouteMatchers } from './Matchers';
17
- import { LookupStore } from './LookupStore';
18
- /**
19
- * Router class exposes unified API to create new routes, group them or
20
- * create route resources.
21
- *
22
- * @example
23
- * ```ts
24
- * const router = new Router()
25
- *
26
- * router.get('/', async function () {
27
- * // handle request
28
- * })
29
- * ```
30
- */
31
- export declare class Router extends LookupStore implements RouterContract {
32
- private routeProcessor?;
33
- /**
34
- * Collection of routes, including route resource and route
35
- * group. To get a flat list of routes, call `router.toJSON()`
36
- */
37
- routes: (Route | RouteResource | RouteGroup | BriskRoute)[];
38
- /**
39
- * Exposing BriskRoute, RouteGroup and RouteResource constructors
40
- * to be extended from outside
41
- */
42
- BriskRoute: typeof BriskRoute;
43
- RouteGroup: typeof RouteGroup;
44
- RouteResource: typeof RouteResource;
45
- Route: typeof Route;
46
- RouteMatchers: typeof RouteMatchers;
47
- /**
48
- * Shortcut methods for commonly used route matchers
49
- */
50
- matchers: RouteMatchers;
51
- /**
52
- * Global matchers to test route params against regular expressions.
53
- */
54
- private paramMatchers;
55
- /**
56
- * Store with tokenized routes
57
- */
58
- private store;
59
- /**
60
- * A boolean to tell the router that a group is in
61
- * open state right now
62
- */
63
- private openedGroups;
64
- private getRecentGroup;
65
- constructor(encryption: EncryptionContract, routeProcessor?: ((route: RouteNode) => void) | undefined);
66
- /**
67
- * Add route for a given pattern and methods
68
- */
69
- route(pattern: string, methods: string[], handler: RouteHandler): Route;
70
- /**
71
- * Define a route that handles all common HTTP methods
72
- */
73
- any(pattern: string, handler: RouteHandler): Route;
74
- /**
75
- * Define `GET` route
76
- */
77
- get(pattern: string, handler: RouteHandler): Route;
78
- /**
79
- * Define `POST` route
80
- */
81
- post(pattern: string, handler: RouteHandler): Route;
82
- /**
83
- * Define `PUT` route
84
- */
85
- put(pattern: string, handler: RouteHandler): Route;
86
- /**
87
- * Define `PATCH` route
88
- */
89
- patch(pattern: string, handler: RouteHandler): Route;
90
- /**
91
- * Define `DELETE` route
92
- */
93
- delete(pattern: string, handler: RouteHandler): Route;
94
- /**
95
- * Creates a group of routes. A route group can apply transforms
96
- * to routes in bulk
97
- */
98
- group(callback: () => void): RouteGroup;
99
- /**
100
- * Registers a route resource with conventional set of routes
101
- */
102
- resource(resource: string, controller: string): RouteResource;
103
- /**
104
- * Register a route resource with shallow nested routes.
105
- */
106
- shallowResource(resource: string, controller: string): RouteResource;
107
- /**
108
- * Returns a brisk route instance for a given URL pattern
109
- */
110
- on(pattern: string): BriskRoute;
111
- /**
112
- * Define global route matcher
113
- */
114
- where(param: string, matcher: string | RegExp): this;
115
- /**
116
- * Returns a flat list of routes JSON
117
- */
118
- toJSON(): {
119
- [domain: string]: (RouteNode & {
120
- methods: string[];
121
- })[];
122
- };
123
- /**
124
- * Commit routes to the store. After this, no more
125
- * routes can be registered.
126
- */
127
- commit(): void;
128
- /**
129
- * Find route for a given URL, method and optionally domain
130
- */
131
- match(url: string, method: string, domain?: string): null | MatchedRoute;
132
- /**
133
- * Makes url to a registered route by looking it up with the route pattern,
134
- * name or the controller.method
135
- */
136
- makeUrl(routeIdentifier: string, params?: any[] | MakeUrlOptions, options?: MakeUrlOptions): string;
137
- /**
138
- * Makes a signed url, which can be confirmed for it's integrity without
139
- * relying on any sort of backend storage.
140
- */
141
- makeSignedUrl(routeIdentifier: string, params?: any[] | MakeSignedUrlOptions, options?: MakeSignedUrlOptions): string;
142
- }
@@ -1,333 +0,0 @@
1
- "use strict";
2
- /**
3
- * @adonisjs/http-server
4
- *
5
- * (c) Harminder Virk <virk@adonisjs.com>
6
- *
7
- * For the full copyright and license information, please view the LICENSE
8
- * file that was distributed with this source code.
9
- */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.Router = void 0;
12
- /// <reference path="../../adonis-typings/index.ts" />
13
- const helpers_1 = require("@poppinss/utils/build/helpers");
14
- const Route_1 = require("./Route");
15
- const Store_1 = require("./Store");
16
- const Group_1 = require("./Group");
17
- const BriskRoute_1 = require("./BriskRoute");
18
- const Resource_1 = require("./Resource");
19
- const RouterException_1 = require("../Exceptions/RouterException");
20
- const helpers_2 = require("../helpers");
21
- const Matchers_1 = require("./Matchers");
22
- const LookupStore_1 = require("./LookupStore");
23
- /**
24
- * Router class exposes unified API to create new routes, group them or
25
- * create route resources.
26
- *
27
- * @example
28
- * ```ts
29
- * const router = new Router()
30
- *
31
- * router.get('/', async function () {
32
- * // handle request
33
- * })
34
- * ```
35
- */
36
- class Router extends LookupStore_1.LookupStore {
37
- constructor(encryption, routeProcessor) {
38
- super(encryption);
39
- this.routeProcessor = routeProcessor;
40
- /**
41
- * Collection of routes, including route resource and route
42
- * group. To get a flat list of routes, call `router.toJSON()`
43
- */
44
- this.routes = [];
45
- /**
46
- * Exposing BriskRoute, RouteGroup and RouteResource constructors
47
- * to be extended from outside
48
- */
49
- this.BriskRoute = BriskRoute_1.BriskRoute;
50
- this.RouteGroup = Group_1.RouteGroup;
51
- this.RouteResource = Resource_1.RouteResource;
52
- this.Route = Route_1.Route;
53
- this.RouteMatchers = Matchers_1.RouteMatchers;
54
- /**
55
- * Shortcut methods for commonly used route matchers
56
- */
57
- this.matchers = new Matchers_1.RouteMatchers();
58
- /**
59
- * Global matchers to test route params against regular expressions.
60
- */
61
- this.paramMatchers = {};
62
- /**
63
- * Store with tokenized routes
64
- */
65
- this.store = new Store_1.Store();
66
- /**
67
- * A boolean to tell the router that a group is in
68
- * open state right now
69
- */
70
- this.openedGroups = [];
71
- }
72
- getRecentGroup() {
73
- return this.openedGroups[this.openedGroups.length - 1];
74
- }
75
- /**
76
- * Add route for a given pattern and methods
77
- */
78
- route(pattern, methods, handler) {
79
- const route = new Route_1.Route(pattern, methods, handler, this.paramMatchers);
80
- const openedGroup = this.getRecentGroup();
81
- if (openedGroup) {
82
- openedGroup.routes.push(route);
83
- }
84
- else {
85
- this.routes.push(route);
86
- }
87
- return route;
88
- }
89
- /**
90
- * Define a route that handles all common HTTP methods
91
- */
92
- any(pattern, handler) {
93
- return this.route(pattern, ['HEAD', 'OPTIONS', 'GET', 'POST', 'PUT', 'PATCH', 'DELETE'], handler);
94
- }
95
- /**
96
- * Define `GET` route
97
- */
98
- get(pattern, handler) {
99
- return this.route(pattern, ['GET', 'HEAD'], handler);
100
- }
101
- /**
102
- * Define `POST` route
103
- */
104
- post(pattern, handler) {
105
- return this.route(pattern, ['POST'], handler);
106
- }
107
- /**
108
- * Define `PUT` route
109
- */
110
- put(pattern, handler) {
111
- return this.route(pattern, ['PUT'], handler);
112
- }
113
- /**
114
- * Define `PATCH` route
115
- */
116
- patch(pattern, handler) {
117
- return this.route(pattern, ['PATCH'], handler);
118
- }
119
- /**
120
- * Define `DELETE` route
121
- */
122
- delete(pattern, handler) {
123
- return this.route(pattern, ['DELETE'], handler);
124
- }
125
- /**
126
- * Creates a group of routes. A route group can apply transforms
127
- * to routes in bulk
128
- */
129
- group(callback) {
130
- /*
131
- * Create a new group with empty set of routes
132
- */
133
- const group = new Group_1.RouteGroup([]);
134
- /*
135
- * See if there is any opened existing route groups. If yes, then we
136
- * push this new group to the old group, otherwise we push it to
137
- * the list of routes.
138
- */
139
- const openedGroup = this.getRecentGroup();
140
- if (openedGroup) {
141
- openedGroup.routes.push(group);
142
- }
143
- else {
144
- this.routes.push(group);
145
- }
146
- /*
147
- * Track the group, so that the upcoming calls inside the callback
148
- * can use this group
149
- */
150
- this.openedGroups.push(group);
151
- /*
152
- * Execute the callback. Now all registered routes will be
153
- * collected seperately from the `routes` array
154
- */
155
- callback();
156
- /*
157
- * Now the callback is over, get rid of the opened group
158
- */
159
- this.openedGroups.pop();
160
- return group;
161
- }
162
- /**
163
- * Registers a route resource with conventional set of routes
164
- */
165
- resource(resource, controller) {
166
- const resourceInstance = new Resource_1.RouteResource(resource, controller, this.paramMatchers);
167
- const openedGroup = this.getRecentGroup();
168
- if (openedGroup) {
169
- openedGroup.routes.push(resourceInstance);
170
- }
171
- else {
172
- this.routes.push(resourceInstance);
173
- }
174
- return resourceInstance;
175
- }
176
- /**
177
- * Register a route resource with shallow nested routes.
178
- */
179
- shallowResource(resource, controller) {
180
- const resourceInstance = new Resource_1.RouteResource(resource, controller, this.paramMatchers, true);
181
- const openedGroup = this.getRecentGroup();
182
- if (openedGroup) {
183
- openedGroup.routes.push(resourceInstance);
184
- }
185
- else {
186
- this.routes.push(resourceInstance);
187
- }
188
- return resourceInstance;
189
- }
190
- /**
191
- * Returns a brisk route instance for a given URL pattern
192
- */
193
- on(pattern) {
194
- const briskRoute = new BriskRoute_1.BriskRoute(pattern, this.paramMatchers);
195
- const openedGroup = this.getRecentGroup();
196
- if (openedGroup) {
197
- openedGroup.routes.push(briskRoute);
198
- }
199
- else {
200
- this.routes.push(briskRoute);
201
- }
202
- return briskRoute;
203
- }
204
- /**
205
- * Define global route matcher
206
- */
207
- where(param, matcher) {
208
- if (typeof matcher === 'string') {
209
- this.paramMatchers[param] = { match: new RegExp(matcher) };
210
- }
211
- else if (helpers_1.types.isRegexp(matcher)) {
212
- this.paramMatchers[param] = { match: matcher };
213
- }
214
- else {
215
- this.paramMatchers[param] = matcher;
216
- }
217
- return this;
218
- }
219
- /**
220
- * Returns a flat list of routes JSON
221
- */
222
- toJSON() {
223
- const lookupStoreRoutes = this.tree;
224
- const domains = Object.keys(lookupStoreRoutes);
225
- return domains.reduce((result, domain) => {
226
- result[domain] = lookupStoreRoutes[domain].map((route) => {
227
- const routeJSON = this.store.tree.domains[domain][route.methods[0]].routes[route.pattern];
228
- return Object.assign({ methods: route.methods }, routeJSON);
229
- });
230
- return result;
231
- }, {});
232
- }
233
- /**
234
- * Commit routes to the store. After this, no more
235
- * routes can be registered.
236
- */
237
- commit() {
238
- const names = [];
239
- (0, helpers_2.toRoutesJSON)(this.routes).forEach((route) => {
240
- /*
241
- * Raise error when route name is already in use. Route names have to be unique
242
- * to ensure that only one route is returned during lookup.
243
- */
244
- if (route.name && names.indexOf(route.name) > -1) {
245
- throw RouterException_1.RouterException.duplicateRouteName(route.name);
246
- }
247
- /*
248
- * If route has a unique, then track the name for checking duplicates
249
- */
250
- if (route.name) {
251
- names.push(route.name);
252
- }
253
- /*
254
- * If a pre-processor is defined then pass the [[RouteNode]]
255
- * to it.
256
- */
257
- if (this.routeProcessor) {
258
- this.routeProcessor(route);
259
- }
260
- /**
261
- * Register the route with the lookup store
262
- */
263
- this.register(route);
264
- this.store.add(route);
265
- });
266
- this.routes = [];
267
- this.paramMatchers = {};
268
- }
269
- /**
270
- * Find route for a given URL, method and optionally domain
271
- */
272
- match(url, method, domain) {
273
- /*
274
- * 1. If domain is not mentioned, then we lookup for root level defined
275
- * routes.
276
- *
277
- * 2. If domain is mentioned, then we check the store to see if user has registered
278
- * one or more routes for that domain or not.
279
- *
280
- * - If they have not registered any routes for the mentioned domain, it means,
281
- * they don't want any special treatment for this domain, hence we search
282
- * with the the root level routes. (Same as 1)
283
- *
284
- * - Else we search within the routes of the mentioned domain.
285
- */
286
- let response = null;
287
- const matchingDomain = domain ? this.store.matchDomain(domain) : [];
288
- if (!matchingDomain.length) {
289
- response = this.store.match(url, method);
290
- }
291
- else {
292
- /*
293
- * Search within the domain
294
- */
295
- response = this.store.match(url, method, {
296
- storeMatch: matchingDomain,
297
- value: domain,
298
- });
299
- }
300
- return response;
301
- }
302
- /**
303
- * Makes url to a registered route by looking it up with the route pattern,
304
- * name or the controller.method
305
- */
306
- makeUrl(routeIdentifier, params, options) {
307
- const normalizedOptions = (0, helpers_2.normalizeMakeUrlOptions)(params, options);
308
- const builder = normalizedOptions.domain
309
- ? this.builderForDomain(normalizedOptions.domain)
310
- : this.builder();
311
- normalizedOptions.params && builder.params(normalizedOptions.params);
312
- normalizedOptions.qs && builder.qs(normalizedOptions.qs);
313
- normalizedOptions.prefixUrl && builder.prefixUrl(normalizedOptions.prefixUrl);
314
- normalizedOptions.disableRouteLookup && builder.disableRouteLookup();
315
- return builder.make(routeIdentifier);
316
- }
317
- /**
318
- * Makes a signed url, which can be confirmed for it's integrity without
319
- * relying on any sort of backend storage.
320
- */
321
- makeSignedUrl(routeIdentifier, params, options) {
322
- const normalizedOptions = (0, helpers_2.normalizeMakeSignedUrlOptions)(params, options);
323
- const builder = normalizedOptions.domain
324
- ? this.builderForDomain(normalizedOptions.domain)
325
- : this.builder();
326
- normalizedOptions.params && builder.params(normalizedOptions.params);
327
- normalizedOptions.qs && builder.qs(normalizedOptions.qs);
328
- normalizedOptions.prefixUrl && builder.prefixUrl(normalizedOptions.prefixUrl);
329
- normalizedOptions.disableRouteLookup && builder.disableRouteLookup();
330
- return builder.makeSigned(routeIdentifier, normalizedOptions);
331
- }
332
- }
333
- exports.Router = Router;
@@ -1,49 +0,0 @@
1
- /**
2
- * @adonisjs/http-server
3
- *
4
- * (c) Harminder Virk <virk@adonisjs.com>
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- /// <reference path="../../../adonis-typings/index.d.ts" />
10
- import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext';
11
- import { ErrorHandler } from '@ioc:Adonis/Core/Server';
12
- import { IocContract } from '@adonisjs/fold';
13
- /**
14
- * Exception manager exposes the API to register custom error handler
15
- * and invoke it when exceptions are raised during the HTTP
16
- * lifecycle.
17
- */
18
- export declare class ExceptionManager {
19
- /**
20
- * Resolved copy of error handler
21
- */
22
- private resolvedErrorHandler?;
23
- /**
24
- * Resolved copy of error reporter
25
- */
26
- private resolvedErrorReporter?;
27
- /**
28
- * A reference to ioc resolver to resolve the error handler from
29
- * the IoC container
30
- */
31
- private resolver;
32
- constructor(container: IocContract);
33
- /**
34
- * Register a custom error handler
35
- */
36
- registerHandler(handler: ErrorHandler): void;
37
- /**
38
- * Handle error
39
- */
40
- private handleError;
41
- /**
42
- * Report error when report method exists
43
- */
44
- private reportError;
45
- /**
46
- * Handle the error
47
- */
48
- handle(error: any, ctx: HttpContextContract): Promise<void>;
49
- }
@@ -1,96 +0,0 @@
1
- "use strict";
2
- /**
3
- * @adonisjs/http-server
4
- *
5
- * (c) Harminder Virk <virk@adonisjs.com>
6
- *
7
- * For the full copyright and license information, please view the LICENSE
8
- * file that was distributed with this source code.
9
- */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.ExceptionManager = void 0;
12
- const helpers_1 = require("../../helpers");
13
- /**
14
- * Exception manager exposes the API to register custom error handler
15
- * and invoke it when exceptions are raised during the HTTP
16
- * lifecycle.
17
- */
18
- class ExceptionManager {
19
- constructor(container) {
20
- this.resolver = container.getResolver();
21
- }
22
- /**
23
- * Register a custom error handler
24
- */
25
- registerHandler(handler) {
26
- if (typeof handler === 'string') {
27
- this.resolvedErrorHandler = this.resolver.resolve(`${handler}.handle`);
28
- this.resolvedErrorReporter = this.resolver.resolve(`${handler}.report`);
29
- }
30
- else {
31
- this.resolvedErrorHandler = {
32
- type: 'function',
33
- value: handler,
34
- };
35
- }
36
- }
37
- /**
38
- * Handle error
39
- */
40
- async handleError(error, ctx) {
41
- ctx.response.safeStatus(error.status || 500);
42
- /*
43
- * Make response when no error handler has been registered
44
- */
45
- if (!this.resolvedErrorHandler) {
46
- ctx.response.send(error.message);
47
- return;
48
- }
49
- /*
50
- * Invoke the error handler and catch any errors raised by the error
51
- * handler itself. We don't expect error handlers to raise exceptions.
52
- * However, during development a broken error handler may raise
53
- * exceptions.
54
- */
55
- try {
56
- let value = null;
57
- if (this.resolvedErrorHandler.type === 'function') {
58
- value = await this.resolvedErrorHandler.value(error, ctx);
59
- }
60
- else {
61
- value = await this.resolver.call(this.resolvedErrorHandler, undefined, [error, ctx]);
62
- }
63
- if ((0, helpers_1.useReturnValue)(value, ctx)) {
64
- ctx.response.send(value);
65
- }
66
- }
67
- catch (finalError) {
68
- /*
69
- * Unexpected block
70
- */
71
- ctx.response.status(error.status || 500).send(error.message);
72
- ctx.logger.fatal(finalError, 'Unexpected exception raised from HTTP ExceptionHandler "handle" method');
73
- }
74
- }
75
- /**
76
- * Report error when report method exists
77
- */
78
- async reportError(error, ctx) {
79
- if (this.resolvedErrorReporter) {
80
- try {
81
- await this.resolver.call(this.resolvedErrorReporter, undefined, [error, ctx]);
82
- }
83
- catch (finalError) {
84
- ctx.logger.fatal(finalError, 'Unexpected exception raised from HTTP ExceptionHandler "report" method');
85
- }
86
- }
87
- }
88
- /**
89
- * Handle the error
90
- */
91
- async handle(error, ctx) {
92
- await this.handleError(error, ctx);
93
- this.reportError(error, ctx);
94
- }
95
- }
96
- exports.ExceptionManager = ExceptionManager;
@@ -1,43 +0,0 @@
1
- /**
2
- * @adonisjs/http-server
3
- *
4
- * (c) Harminder Virk <virk@adonisjs.com>
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- /// <reference path="../../../adonis-typings/index.d.ts" />
10
- import { HookHandler, HooksContract } from '@ioc:Adonis/Core/Server';
11
- import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext';
12
- /**
13
- * Exposes to API to register and execute before and after hooks
14
- */
15
- export declare class Hooks implements HooksContract {
16
- /**
17
- * Registered before and after hooks
18
- */
19
- private hooks;
20
- /**
21
- * Register before hook
22
- */
23
- before(cb: HookHandler): this;
24
- /**
25
- * Register after hook
26
- */
27
- after(cb: HookHandler): this;
28
- /**
29
- * Executing before hooks in series. If this method returns `true`,
30
- * it means that one of the before hooks wants to end the request
31
- * without further processing it.
32
- */
33
- executeBefore(ctx: HttpContextContract): Promise<boolean>;
34
- /**
35
- * Executes after hooks in series.
36
- */
37
- executeAfter(ctx: HttpContextContract): Promise<void>;
38
- /**
39
- * The commit action enables us to optimize the hook handlers
40
- * for runtime peformance
41
- */
42
- commit(): void;
43
- }