@adonisjs/http-server 7.0.0-1 → 7.0.0-2

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 (62) hide show
  1. package/build/chunk-Z63E3STR.js +4436 -0
  2. package/build/chunk-Z63E3STR.js.map +1 -0
  3. package/build/factories/main.js +332 -14
  4. package/build/factories/main.js.map +1 -0
  5. package/build/index.js +309 -22
  6. package/build/index.js.map +1 -0
  7. package/build/src/router/lookup_store/main.d.ts +1 -3
  8. package/build/src/router/lookup_store/route_finder.d.ts +5 -1
  9. package/build/src/router/main.d.ts +2 -2
  10. package/build/src/router/resource.d.ts +19 -7
  11. package/build/src/types/main.js +1 -15
  12. package/build/src/types/main.js.map +1 -0
  13. package/package.json +52 -51
  14. package/build/factories/http_context.js +0 -51
  15. package/build/factories/http_server.js +0 -26
  16. package/build/factories/qs_parser_factory.js +0 -44
  17. package/build/factories/request.js +0 -73
  18. package/build/factories/response.js +0 -77
  19. package/build/factories/router.js +0 -45
  20. package/build/factories/server_factory.js +0 -65
  21. package/build/src/cookies/client.js +0 -84
  22. package/build/src/cookies/drivers/encrypted.js +0 -36
  23. package/build/src/cookies/drivers/plain.js +0 -33
  24. package/build/src/cookies/drivers/signed.js +0 -36
  25. package/build/src/cookies/parser.js +0 -167
  26. package/build/src/cookies/serializer.js +0 -79
  27. package/build/src/debug.js +0 -10
  28. package/build/src/define_config.js +0 -68
  29. package/build/src/define_middleware.js +0 -35
  30. package/build/src/exception_handler.js +0 -306
  31. package/build/src/exceptions.js +0 -38
  32. package/build/src/helpers.js +0 -105
  33. package/build/src/http_context/local_storage.js +0 -39
  34. package/build/src/http_context/main.js +0 -105
  35. package/build/src/qs.js +0 -25
  36. package/build/src/redirect.js +0 -140
  37. package/build/src/request.js +0 -865
  38. package/build/src/response.js +0 -1208
  39. package/build/src/router/brisk.js +0 -85
  40. package/build/src/router/executor.js +0 -30
  41. package/build/src/router/factories/use_return_value.js +0 -22
  42. package/build/src/router/group.js +0 -207
  43. package/build/src/router/lookup_store/main.js +0 -86
  44. package/build/src/router/lookup_store/route_finder.js +0 -49
  45. package/build/src/router/lookup_store/url_builder.js +0 -209
  46. package/build/src/router/main.js +0 -316
  47. package/build/src/router/matchers.js +0 -36
  48. package/build/src/router/parser.js +0 -17
  49. package/build/src/router/resource.js +0 -216
  50. package/build/src/router/route.js +0 -293
  51. package/build/src/router/store.js +0 -195
  52. package/build/src/server/factories/final_handler.js +0 -30
  53. package/build/src/server/factories/middleware_handler.js +0 -16
  54. package/build/src/server/factories/write_response.js +0 -24
  55. package/build/src/server/main.js +0 -292
  56. package/build/src/types/base.js +0 -9
  57. package/build/src/types/middleware.js +0 -9
  58. package/build/src/types/qs.js +0 -9
  59. package/build/src/types/request.js +0 -9
  60. package/build/src/types/response.js +0 -9
  61. package/build/src/types/route.js +0 -9
  62. package/build/src/types/server.js +0 -9
@@ -1,292 +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
- import onFinished from 'on-finished';
10
- import Middleware from '@poppinss/middleware';
11
- import { moduleCaller, moduleImporter } from '@adonisjs/fold';
12
- import { Qs } from '../qs.js';
13
- import debug from '../debug.js';
14
- import { Request } from '../request.js';
15
- import { Response } from '../response.js';
16
- import { Router } from '../router/main.js';
17
- import { HttpContext } from '../http_context/main.js';
18
- import { finalHandler } from './factories/final_handler.js';
19
- import { writeResponse } from './factories/write_response.js';
20
- import { asyncLocalStorage } from '../http_context/local_storage.js';
21
- import { middlewareHandler } from './factories/middleware_handler.js';
22
- /**
23
- * The HTTP server implementation to handle incoming requests and respond using the
24
- * registered routes.
25
- */
26
- export class Server {
27
- /**
28
- * The default error handler to use
29
- */
30
- #defaultErrorHandler = {
31
- report() { },
32
- handle(error, ctx) {
33
- ctx.response.status(error.status || 500).send(error.message || 'Internal server error');
34
- },
35
- };
36
- /**
37
- * Logger instance, a child logger is added
38
- * to the context to have request specific
39
- * logging capabilities.
40
- */
41
- #logger;
42
- /**
43
- * Registered error handler (if any)
44
- */
45
- #errorHandler;
46
- /**
47
- * Resolved error handler is an instance of the lazily imported error
48
- * handler class.
49
- */
50
- #resolvedErrorHandler = this.#defaultErrorHandler;
51
- /**
52
- * Emitter is required to notify when a request finishes
53
- */
54
- #emitter;
55
- /**
56
- * The application instance to be shared with the router
57
- */
58
- #app;
59
- /**
60
- * The encryption instance to be shared with the router
61
- */
62
- #encryption;
63
- /**
64
- * Server config
65
- */
66
- #config;
67
- /**
68
- * Query string parser used by the server
69
- */
70
- #qsParser;
71
- /**
72
- * Server middleware stack runs on every incoming HTTP request
73
- */
74
- #serverMiddlewareStack;
75
- /**
76
- * Reference to the router used by the server
77
- */
78
- #router;
79
- /**
80
- * Reference to the underlying Node HTTP server in use
81
- */
82
- #nodeHttpServer;
83
- /**
84
- * Middleware store to be shared with the routes
85
- */
86
- #middleware = [];
87
- /**
88
- * The request error response is attached to the middleware
89
- * pipeline to intercept errors and invoke the user
90
- * registered error handler.
91
- *
92
- * We share this with the route middleware pipeline as well,
93
- * so that it does not throw any exceptions
94
- */
95
- #requestErrorResponder = (error, ctx) => {
96
- this.#resolvedErrorHandler.report(error, ctx);
97
- return this.#resolvedErrorHandler.handle(error, ctx);
98
- };
99
- /**
100
- * Know if async local storage is enabled or not.
101
- */
102
- get usingAsyncLocalStorage() {
103
- return asyncLocalStorage.isEnabled;
104
- }
105
- constructor(app, encryption, emitter, logger, config) {
106
- this.#app = app;
107
- this.#emitter = emitter;
108
- this.#config = config;
109
- this.#logger = logger;
110
- this.#encryption = encryption;
111
- this.#qsParser = new Qs(this.#config.qs);
112
- this.#router = new Router(this.#app, this.#encryption, this.#qsParser);
113
- this.#createAsyncLocalStore();
114
- debug('server config: %O', this.#config);
115
- }
116
- /**
117
- * Create async local storage store when enabled
118
- */
119
- #createAsyncLocalStore() {
120
- if (this.#config.useAsyncLocalStorage) {
121
- debug('creating ALS store for HTTP context');
122
- asyncLocalStorage.create();
123
- }
124
- else {
125
- asyncLocalStorage.destroy();
126
- }
127
- }
128
- /**
129
- * Creates an instance of the server middleware stack
130
- */
131
- #createServerMiddlewareStack() {
132
- this.#serverMiddlewareStack = new Middleware();
133
- this.#middleware.forEach((middleware) => this.#serverMiddlewareStack.add(middleware));
134
- this.#serverMiddlewareStack.freeze();
135
- this.#middleware = [];
136
- }
137
- /**
138
- * Handles the HTTP request
139
- */
140
- #handleRequest(ctx, resolver) {
141
- return this.#serverMiddlewareStack.runner()
142
- .errorHandler((error) => this.#requestErrorResponder(error, ctx))
143
- .finalHandler(finalHandler(this.#router, resolver, ctx, this.#requestErrorResponder))
144
- .run(middlewareHandler(resolver, ctx))
145
- .catch((error) => {
146
- ctx.logger.fatal({ err: error }, 'Exception raised by error handler');
147
- return this.#defaultErrorHandler.handle(error, ctx);
148
- })
149
- .finally(writeResponse(ctx));
150
- }
151
- /**
152
- * Creates a pipeline of middleware.
153
- */
154
- pipeline(middleware) {
155
- const middlewareStack = new Middleware();
156
- middleware.forEach((one) => {
157
- middlewareStack.add(moduleCaller(one, 'handle').toHandleMethod());
158
- });
159
- middlewareStack.freeze();
160
- const stackRunner = middlewareStack.runner();
161
- return {
162
- finalHandler(handler) {
163
- stackRunner.finalHandler(handler);
164
- return this;
165
- },
166
- errorHandler(handler) {
167
- stackRunner.errorHandler(handler);
168
- return this;
169
- },
170
- run(ctx) {
171
- return stackRunner.run((handler, next) => {
172
- return handler.handle(ctx.containerResolver, ctx, next);
173
- });
174
- },
175
- };
176
- }
177
- /**
178
- * Define an array of middleware to use on all the incoming HTTP request.
179
- * Calling this method multiple times pushes to the existing list
180
- * of middleware
181
- */
182
- use(middleware) {
183
- middleware.forEach((one) => this.#middleware.push(moduleImporter(one, 'handle').toHandleMethod()));
184
- return this;
185
- }
186
- /**
187
- * Register a custom error handler for HTTP requests.
188
- * All errors will be reported to this method
189
- */
190
- errorHandler(handler) {
191
- this.#errorHandler = handler;
192
- return this;
193
- }
194
- /**
195
- * Boot the server. Calling this method performs the following actions.
196
- *
197
- * - Register routes with the store.
198
- * - Resolve and construct the error handler.
199
- */
200
- async boot() {
201
- debug('booting HTTP server');
202
- /**
203
- * Creates the middleware stack for the server
204
- */
205
- this.#createServerMiddlewareStack();
206
- /**
207
- * Commit routes
208
- */
209
- this.#router.commit();
210
- /**
211
- * Register custom error handler
212
- */
213
- if (this.#errorHandler) {
214
- if (debug.enabled) {
215
- debug('using custom error handler "%s"', this.#errorHandler);
216
- }
217
- const moduleExports = await this.#errorHandler();
218
- this.#resolvedErrorHandler = await this.#app.container.make(moduleExports.default);
219
- }
220
- }
221
- /**
222
- * Set the HTTP server instance used to listen for requests.
223
- */
224
- setNodeServer(server) {
225
- this.#nodeHttpServer = server;
226
- }
227
- /**
228
- * Returns reference to the underlying HTTP server
229
- * in use
230
- */
231
- getNodeServer() {
232
- return this.#nodeHttpServer;
233
- }
234
- /**
235
- * Returns reference to the router instance used
236
- * by the server.
237
- */
238
- getRouter() {
239
- return this.#router;
240
- }
241
- /**
242
- * Creates an instance of the [[Request]] class
243
- */
244
- createRequest(req, res) {
245
- return new Request(req, res, this.#encryption, this.#config, this.#qsParser);
246
- }
247
- /**
248
- * Creates an instance of the [[Response]] class
249
- */
250
- createResponse(req, res) {
251
- return new Response(req, res, this.#encryption, this.#config, this.#router, this.#qsParser);
252
- }
253
- /**
254
- * Creates an instance of the [[HttpContext]] class
255
- */
256
- createHttpContext(request, response, resolver) {
257
- return new HttpContext(request, response, this.#logger.child({ request_id: request.id() }), resolver);
258
- }
259
- /**
260
- * Handle request
261
- */
262
- handle(req, res) {
263
- /**
264
- * Setup for the "http:request_finished" event
265
- */
266
- const hasRequestListener = this.#emitter.hasListeners('http:request_finished');
267
- const startTime = hasRequestListener ? process.hrtime() : null;
268
- /**
269
- * Creating essential instances
270
- */
271
- const resolver = this.#app.container.createResolver();
272
- const ctx = this.createHttpContext(this.createRequest(req, res), this.createResponse(req, res), resolver);
273
- /**
274
- * Emit event when listening for the request_finished event
275
- */
276
- if (startTime) {
277
- onFinished(res, () => {
278
- this.#emitter.emit('http:request_finished', {
279
- ctx: ctx,
280
- duration: process.hrtime(startTime),
281
- });
282
- });
283
- }
284
- /**
285
- * Handle request
286
- */
287
- if (this.usingAsyncLocalStorage) {
288
- return asyncLocalStorage.storage.run(ctx, () => this.#handleRequest(ctx, resolver));
289
- }
290
- return this.#handleRequest(ctx, resolver);
291
- }
292
- }
@@ -1,9 +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
- export {};
@@ -1,9 +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
- export {};
@@ -1,9 +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
- export {};
@@ -1,9 +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
- export {};
@@ -1,9 +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
- export {};
@@ -1,9 +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
- export {};
@@ -1,9 +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
- export {};