@adonisjs/http-server 6.8.2-9 → 7.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 (107) hide show
  1. package/build/chunk-XX72ATFY.js +4388 -0
  2. package/build/factories/main.d.ts +149 -6
  3. package/build/factories/main.js +331 -14
  4. package/build/index.d.ts +272 -14
  5. package/build/index.js +308 -22
  6. package/build/{src/server/main.d.ts → main-29eaaee4.d.ts} +12 -17
  7. package/build/main-e5b46c83.d.ts +2210 -0
  8. package/build/src/types/main.d.ts +14 -7
  9. package/build/src/types/main.js +0 -15
  10. package/package.json +62 -53
  11. package/build/factories/http_context.d.ts +0 -25
  12. package/build/factories/http_context.js +0 -51
  13. package/build/factories/http_server.d.ts +0 -8
  14. package/build/factories/http_server.js +0 -26
  15. package/build/factories/qs_parser_factory.d.ts +0 -20
  16. package/build/factories/qs_parser_factory.js +0 -44
  17. package/build/factories/request.d.ts +0 -29
  18. package/build/factories/request.js +0 -73
  19. package/build/factories/response.d.ts +0 -29
  20. package/build/factories/response.js +0 -77
  21. package/build/factories/router.d.ts +0 -23
  22. package/build/factories/router.js +0 -45
  23. package/build/factories/server_factory.d.ts +0 -29
  24. package/build/factories/server_factory.js +0 -65
  25. package/build/src/cookies/client.d.ts +0 -37
  26. package/build/src/cookies/client.js +0 -84
  27. package/build/src/cookies/drivers/encrypted.d.ts +0 -16
  28. package/build/src/cookies/drivers/encrypted.js +0 -36
  29. package/build/src/cookies/drivers/plain.d.ts +0 -15
  30. package/build/src/cookies/drivers/plain.js +0 -33
  31. package/build/src/cookies/drivers/signed.d.ts +0 -16
  32. package/build/src/cookies/drivers/signed.js +0 -36
  33. package/build/src/cookies/parser.d.ts +0 -37
  34. package/build/src/cookies/parser.js +0 -167
  35. package/build/src/cookies/serializer.d.ts +0 -33
  36. package/build/src/cookies/serializer.js +0 -79
  37. package/build/src/debug.d.ts +0 -3
  38. package/build/src/debug.js +0 -10
  39. package/build/src/define_config.d.ts +0 -5
  40. package/build/src/define_config.js +0 -51
  41. package/build/src/define_middleware.d.ts +0 -11
  42. package/build/src/define_middleware.js +0 -35
  43. package/build/src/exception_handler.d.ts +0 -112
  44. package/build/src/exception_handler.js +0 -303
  45. package/build/src/exceptions.d.ts +0 -84
  46. package/build/src/exceptions.js +0 -38
  47. package/build/src/helpers.d.ts +0 -23
  48. package/build/src/helpers.js +0 -84
  49. package/build/src/http_context/local_storage.d.ts +0 -12
  50. package/build/src/http_context/local_storage.js +0 -39
  51. package/build/src/http_context/main.d.ts +0 -58
  52. package/build/src/http_context/main.js +0 -105
  53. package/build/src/qs.d.ts +0 -11
  54. package/build/src/qs.js +0 -25
  55. package/build/src/redirect.d.ts +0 -42
  56. package/build/src/redirect.js +0 -140
  57. package/build/src/request.d.ts +0 -565
  58. package/build/src/request.js +0 -865
  59. package/build/src/response.d.ts +0 -540
  60. package/build/src/response.js +0 -1208
  61. package/build/src/router/brisk.d.ts +0 -42
  62. package/build/src/router/brisk.js +0 -85
  63. package/build/src/router/executor.d.ts +0 -8
  64. package/build/src/router/executor.js +0 -29
  65. package/build/src/router/factories/use_return_value.d.ts +0 -6
  66. package/build/src/router/factories/use_return_value.js +0 -22
  67. package/build/src/router/group.d.ts +0 -65
  68. package/build/src/router/group.js +0 -207
  69. package/build/src/router/lookup_store/main.d.ts +0 -49
  70. package/build/src/router/lookup_store/main.js +0 -86
  71. package/build/src/router/lookup_store/route_finder.d.ts +0 -21
  72. package/build/src/router/lookup_store/route_finder.js +0 -49
  73. package/build/src/router/lookup_store/url_builder.d.ts +0 -52
  74. package/build/src/router/lookup_store/url_builder.js +0 -209
  75. package/build/src/router/main.d.ts +0 -128
  76. package/build/src/router/main.js +0 -316
  77. package/build/src/router/matchers.d.ts +0 -27
  78. package/build/src/router/matchers.js +0 -36
  79. package/build/src/router/parser.d.ts +0 -5
  80. package/build/src/router/parser.js +0 -17
  81. package/build/src/router/resource.d.ts +0 -54
  82. package/build/src/router/resource.js +0 -216
  83. package/build/src/router/route.d.ts +0 -92
  84. package/build/src/router/route.js +0 -293
  85. package/build/src/router/store.d.ts +0 -66
  86. package/build/src/router/store.js +0 -195
  87. package/build/src/server/factories/final_handler.d.ts +0 -9
  88. package/build/src/server/factories/final_handler.js +0 -30
  89. package/build/src/server/factories/middleware_handler.d.ts +0 -8
  90. package/build/src/server/factories/middleware_handler.js +0 -16
  91. package/build/src/server/factories/write_response.d.ts +0 -6
  92. package/build/src/server/factories/write_response.js +0 -24
  93. package/build/src/server/main.js +0 -283
  94. package/build/src/types/base.d.ts +0 -19
  95. package/build/src/types/base.js +0 -9
  96. package/build/src/types/middleware.d.ts +0 -35
  97. package/build/src/types/middleware.js +0 -9
  98. package/build/src/types/qs.d.ts +0 -68
  99. package/build/src/types/qs.js +0 -9
  100. package/build/src/types/request.d.ts +0 -39
  101. package/build/src/types/request.js +0 -9
  102. package/build/src/types/response.d.ts +0 -45
  103. package/build/src/types/response.js +0 -9
  104. package/build/src/types/route.d.ts +0 -165
  105. package/build/src/types/route.js +0 -9
  106. package/build/src/types/server.d.ts +0 -72
  107. package/build/src/types/server.js +0 -9
package/build/index.d.ts CHANGED
@@ -1,14 +1,272 @@
1
- export { Request } from './src/request.js';
2
- export { Response } from './src/response.js';
3
- export { Redirect } from './src/redirect.js';
4
- export { Server } from './src/server/main.js';
5
- export { Router } from './src/router/main.js';
6
- export { Route } from './src/router/route.js';
7
- export * as errors from './src/exceptions.js';
8
- export { BriskRoute } from './src/router/brisk.js';
9
- export { RouteGroup } from './src/router/group.js';
10
- export { defineConfig } from './src/define_config.js';
11
- export { CookieClient } from './src/cookies/client.js';
12
- export { HttpContext } from './src/http_context/main.js';
13
- export { RouteResource } from './src/router/resource.js';
14
- export { ExceptionHandler } from './src/exception_handler.js';
1
+ import { H as HttpContext, S as ServerConfig, c as StatusPageRange, d as StatusPageRenderer, e as HttpError } from './main-e5b46c83.js';
2
+ export { B as BriskRoute, f as Redirect, a as Request, b as Response, g as Route, h as RouteGroup, i as RouteResource, R as Router } from './main-e5b46c83.js';
3
+ export { S as Server } from './main-29eaaee4.js';
4
+ import { Exception } from '@poppinss/utils';
5
+ import { Encryption } from '@adonisjs/encryption';
6
+ import Macroable from '@poppinss/macroable';
7
+ import { Level } from '@adonisjs/logger/types';
8
+ import '@adonisjs/fold';
9
+ import '@adonisjs/logger';
10
+ import 'node:url';
11
+ import 'node:http';
12
+ import 'qs';
13
+ import 'http';
14
+ import 'stream';
15
+ import '@poppinss/middleware';
16
+ import '@poppinss/middleware/types';
17
+ import 'node:stream';
18
+ import '@adonisjs/application';
19
+ import '@adonisjs/events';
20
+ import 'node:https';
21
+
22
+ declare const E_ROUTE_NOT_FOUND: new (args: [method: string, url: string], options?: ErrorOptions | undefined) => Exception;
23
+ declare const E_CANNOT_LOOKUP_ROUTE: new (args: [routeIdentifier: string], options?: ErrorOptions | undefined) => Exception;
24
+ declare const E_HTTP_EXCEPTION: {
25
+ new (message?: string | undefined, options?: (ErrorOptions & {
26
+ code?: string | undefined;
27
+ status?: number | undefined;
28
+ }) | undefined): {
29
+ body: any;
30
+ name: string;
31
+ help?: string | undefined;
32
+ code?: string | undefined;
33
+ status: number;
34
+ toString(): string;
35
+ readonly [Symbol.toStringTag]: string;
36
+ message: string;
37
+ stack?: string | undefined;
38
+ cause?: unknown;
39
+ };
40
+ code: string;
41
+ /**
42
+ * This method returns an instance of the exception class
43
+ */
44
+ invoke(body: any, status: number, code?: string): {
45
+ body: any;
46
+ name: string;
47
+ help?: string | undefined;
48
+ code?: string | undefined;
49
+ status: number;
50
+ toString(): string;
51
+ readonly [Symbol.toStringTag]: string;
52
+ message: string;
53
+ stack?: string | undefined;
54
+ cause?: unknown;
55
+ };
56
+ help?: string | undefined;
57
+ status?: number | undefined;
58
+ message?: string | undefined;
59
+ captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
60
+ prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
61
+ stackTraceLimit: number;
62
+ };
63
+ declare const E_HTTP_REQUEST_ABORTED: {
64
+ new (message?: string | undefined, options?: (ErrorOptions & {
65
+ code?: string | undefined;
66
+ status?: number | undefined;
67
+ }) | undefined): {
68
+ handle(error: any, ctx: HttpContext): void;
69
+ body: any;
70
+ name: string;
71
+ help?: string | undefined;
72
+ code?: string | undefined;
73
+ status: number;
74
+ toString(): string;
75
+ readonly [Symbol.toStringTag]: string;
76
+ message: string;
77
+ stack?: string | undefined;
78
+ cause?: unknown;
79
+ };
80
+ code: string;
81
+ /**
82
+ * This method returns an instance of the exception class
83
+ */
84
+ invoke(body: any, status: number, code?: string): {
85
+ body: any;
86
+ name: string;
87
+ help?: string | undefined;
88
+ code?: string | undefined;
89
+ status: number;
90
+ toString(): string;
91
+ readonly [Symbol.toStringTag]: string;
92
+ message: string;
93
+ stack?: string | undefined;
94
+ cause?: unknown;
95
+ };
96
+ help?: string | undefined;
97
+ status?: number | undefined;
98
+ message?: string | undefined;
99
+ captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
100
+ prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
101
+ stackTraceLimit: number;
102
+ };
103
+
104
+ declare const exceptions_E_CANNOT_LOOKUP_ROUTE: typeof E_CANNOT_LOOKUP_ROUTE;
105
+ declare const exceptions_E_HTTP_EXCEPTION: typeof E_HTTP_EXCEPTION;
106
+ declare const exceptions_E_HTTP_REQUEST_ABORTED: typeof E_HTTP_REQUEST_ABORTED;
107
+ declare const exceptions_E_ROUTE_NOT_FOUND: typeof E_ROUTE_NOT_FOUND;
108
+ declare namespace exceptions {
109
+ export {
110
+ exceptions_E_CANNOT_LOOKUP_ROUTE as E_CANNOT_LOOKUP_ROUTE,
111
+ exceptions_E_HTTP_EXCEPTION as E_HTTP_EXCEPTION,
112
+ exceptions_E_HTTP_REQUEST_ABORTED as E_HTTP_REQUEST_ABORTED,
113
+ exceptions_E_ROUTE_NOT_FOUND as E_ROUTE_NOT_FOUND,
114
+ };
115
+ }
116
+
117
+ type UserDefinedServerConfig = Partial<Omit<ServerConfig, 'trustProxy'> & {
118
+ trustProxy: ((address: string, distance: number) => boolean) | boolean | string;
119
+ }>;
120
+ /**
121
+ * Define configuration for the HTTP server
122
+ */
123
+ declare function defineConfig(config: UserDefinedServerConfig): ServerConfig;
124
+
125
+ /**
126
+ * Cookie client exposes the API to parse/set AdonisJS cookies
127
+ * as a client.
128
+ */
129
+ declare class CookieClient {
130
+ #private;
131
+ constructor(encryption: Encryption);
132
+ /**
133
+ * Encrypt a key value pair to be sent in the cookie header
134
+ */
135
+ encrypt(key: string, value: any): string | null;
136
+ /**
137
+ * Sign a key value pair to be sent in the cookie header
138
+ */
139
+ sign(key: string, value: any): string | null;
140
+ /**
141
+ * Encode a key value pair to be sent in the cookie header
142
+ */
143
+ encode(_: string, value: any): string | null;
144
+ /**
145
+ * Unsign a signed cookie value
146
+ */
147
+ unsign(key: string, value: string): any;
148
+ /**
149
+ * Decrypt an encrypted cookie value
150
+ */
151
+ decrypt(key: string, value: string): any;
152
+ /**
153
+ * Decode an encoded cookie value
154
+ */
155
+ decode(_: string, value: string): any;
156
+ /**
157
+ * Parse response cookie
158
+ */
159
+ parse(key: string, value: any): any;
160
+ }
161
+
162
+ /**
163
+ * The base HTTP exception handler one can inherit from to handle
164
+ * HTTP exceptions.
165
+ *
166
+ * The HTTP exception handler has support for
167
+ *
168
+ * - Ability to render exceptions by calling the render method on the exception.
169
+ * - Rendering status pages
170
+ * - Pretty printing errors during development
171
+ * - Transforming errors to JSON or HTML using content negotiation
172
+ * - Reporting errors
173
+ */
174
+ declare class ExceptionHandler extends Macroable {
175
+ #private;
176
+ /**
177
+ * Whether or not to render debug info. When set to true, the errors
178
+ * will have the complete error stack.
179
+ */
180
+ protected debug: boolean;
181
+ /**
182
+ * Whether or not to render status pages. When set to true, the unhandled
183
+ * errors with matching status codes will be rendered using a status
184
+ * page.
185
+ */
186
+ protected renderStatusPages: boolean;
187
+ /**
188
+ * A collection of error status code range and the view to render.
189
+ */
190
+ protected statusPages: Record<StatusPageRange, StatusPageRenderer>;
191
+ /**
192
+ * Enable/disable errors reporting
193
+ */
194
+ protected reportErrors: boolean;
195
+ /**
196
+ * An array of exception classes to ignore when
197
+ * reporting an error
198
+ */
199
+ protected ignoreExceptions: any[];
200
+ /**
201
+ * An array of HTTP status codes to ignore when reporting
202
+ * an error
203
+ */
204
+ protected ignoreStatuses: number[];
205
+ /**
206
+ * An array of error codes to ignore when reporting
207
+ * an error
208
+ */
209
+ protected ignoreCodes: string[];
210
+ /**
211
+ * Error reporting context
212
+ */
213
+ protected context(ctx: HttpContext): any;
214
+ /**
215
+ * Returns the log level for an error based upon the error
216
+ * status code.
217
+ */
218
+ protected getErrorLogLevel(error: HttpError): Level;
219
+ /**
220
+ * A boolean to control if errors should be rendered with
221
+ * all the available debugging info.
222
+ */
223
+ protected isDebuggingEnabled(_: HttpContext): boolean;
224
+ /**
225
+ * Returns a boolean by checking if an error should be reported.
226
+ */
227
+ protected shouldReport(error: HttpError): boolean;
228
+ /**
229
+ * Renders an error to JSON response
230
+ */
231
+ renderErrorAsJSON(error: HttpError, ctx: HttpContext): Promise<void>;
232
+ /**
233
+ * Renders an error to JSON API response
234
+ */
235
+ renderErrorAsJSONAPI(error: HttpError, ctx: HttpContext): Promise<void>;
236
+ /**
237
+ * Renders an error to HTML response
238
+ */
239
+ renderErrorAsHTML(error: HttpError, ctx: HttpContext): Promise<void>;
240
+ /**
241
+ * Renders the validation error message to a JSON
242
+ * response
243
+ */
244
+ renderValidationErrorAsJSON(error: HttpError, ctx: HttpContext): Promise<void>;
245
+ /**
246
+ * Renders the validation error message as per JSON API
247
+ * spec
248
+ */
249
+ renderValidationErrorAsJSONAPI(error: HttpError, ctx: HttpContext): Promise<void>;
250
+ /**
251
+ * Renders the validation error as an HTML string
252
+ */
253
+ renderValidationErrorAsHTML(error: HttpError, ctx: HttpContext): Promise<void>;
254
+ /**
255
+ * Renders the error to response
256
+ */
257
+ renderError(error: HttpError, ctx: HttpContext): Promise<void>;
258
+ /**
259
+ * Renders the validation error to response
260
+ */
261
+ renderValidationError(error: HttpError, ctx: HttpContext): Promise<void>;
262
+ /**
263
+ * Reports an error during an HTTP request
264
+ */
265
+ report(error: unknown, ctx: HttpContext): Promise<void>;
266
+ /**
267
+ * Handles the error during the HTTP request.
268
+ */
269
+ handle(error: unknown, ctx: HttpContext): Promise<any>;
270
+ }
271
+
272
+ export { CookieClient, ExceptionHandler, HttpContext, defineConfig, exceptions as errors };
package/build/index.js CHANGED
@@ -1,22 +1,308 @@
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 { Request } from './src/request.js';
10
- export { Response } from './src/response.js';
11
- export { Redirect } from './src/redirect.js';
12
- export { Server } from './src/server/main.js';
13
- export { Router } from './src/router/main.js';
14
- export { Route } from './src/router/route.js';
15
- export * as errors from './src/exceptions.js';
16
- export { BriskRoute } from './src/router/brisk.js';
17
- export { RouteGroup } from './src/router/group.js';
18
- export { defineConfig } from './src/define_config.js';
19
- export { CookieClient } from './src/cookies/client.js';
20
- export { HttpContext } from './src/http_context/main.js';
21
- export { RouteResource } from './src/router/resource.js';
22
- export { ExceptionHandler } from './src/exception_handler.js';
1
+ import {
2
+ BriskRoute,
3
+ CookieClient,
4
+ E_CANNOT_LOOKUP_ROUTE,
5
+ E_HTTP_EXCEPTION,
6
+ E_HTTP_REQUEST_ABORTED,
7
+ E_ROUTE_NOT_FOUND,
8
+ HttpContext,
9
+ Redirect,
10
+ Request,
11
+ Response,
12
+ Route,
13
+ RouteGroup,
14
+ RouteResource,
15
+ Router,
16
+ Server,
17
+ defineConfig,
18
+ exceptions_exports,
19
+ parseRange
20
+ } from "./chunk-XX72ATFY.js";
21
+
22
+ // src/exception_handler.ts
23
+ import is from "@sindresorhus/is";
24
+ import Macroable from "@poppinss/macroable";
25
+ var ExceptionHandler = class extends Macroable {
26
+ /**
27
+ * Computed from the status pages property
28
+ */
29
+ #expandedStatusPages;
30
+ /**
31
+ * Whether or not to render debug info. When set to true, the errors
32
+ * will have the complete error stack.
33
+ */
34
+ debug = process.env.NODE_ENV !== "production";
35
+ /**
36
+ * Whether or not to render status pages. When set to true, the unhandled
37
+ * errors with matching status codes will be rendered using a status
38
+ * page.
39
+ */
40
+ renderStatusPages = process.env.NODE_ENV === "production";
41
+ /**
42
+ * A collection of error status code range and the view to render.
43
+ */
44
+ statusPages = {};
45
+ /**
46
+ * Enable/disable errors reporting
47
+ */
48
+ reportErrors = true;
49
+ /**
50
+ * An array of exception classes to ignore when
51
+ * reporting an error
52
+ */
53
+ ignoreExceptions = [
54
+ E_HTTP_EXCEPTION,
55
+ E_ROUTE_NOT_FOUND,
56
+ E_CANNOT_LOOKUP_ROUTE,
57
+ E_HTTP_REQUEST_ABORTED
58
+ ];
59
+ /**
60
+ * An array of HTTP status codes to ignore when reporting
61
+ * an error
62
+ */
63
+ ignoreStatuses = [400, 422, 401];
64
+ /**
65
+ * An array of error codes to ignore when reporting
66
+ * an error
67
+ */
68
+ ignoreCodes = [];
69
+ /**
70
+ * Expands status pages
71
+ */
72
+ #expandStatusPages() {
73
+ if (!this.#expandedStatusPages) {
74
+ this.#expandedStatusPages = Object.keys(this.statusPages).reduce(
75
+ (result, range) => {
76
+ const renderer = this.statusPages[range];
77
+ result = Object.assign(result, parseRange(range, renderer));
78
+ return result;
79
+ },
80
+ {}
81
+ );
82
+ }
83
+ return this.#expandedStatusPages;
84
+ }
85
+ /**
86
+ * Forcefully tweaking the type of the error object to
87
+ * have known properties.
88
+ */
89
+ #toHttpError(error) {
90
+ const httpError = is.object(error) ? error : new Error(String(error));
91
+ httpError.message = httpError.message || "Internal server error";
92
+ httpError.status = httpError.status || 500;
93
+ return httpError;
94
+ }
95
+ /**
96
+ * Error reporting context
97
+ */
98
+ context(ctx) {
99
+ const requestId = ctx.request.id();
100
+ return requestId ? {
101
+ "x-request-id": requestId
102
+ } : {};
103
+ }
104
+ /**
105
+ * Returns the log level for an error based upon the error
106
+ * status code.
107
+ */
108
+ getErrorLogLevel(error) {
109
+ if (error.status >= 500) {
110
+ return "error";
111
+ }
112
+ if (error.status >= 400) {
113
+ return "warn";
114
+ }
115
+ return "info";
116
+ }
117
+ /**
118
+ * A boolean to control if errors should be rendered with
119
+ * all the available debugging info.
120
+ */
121
+ isDebuggingEnabled(_) {
122
+ return this.debug;
123
+ }
124
+ /**
125
+ * Returns a boolean by checking if an error should be reported.
126
+ */
127
+ shouldReport(error) {
128
+ if (this.reportErrors === false) {
129
+ return false;
130
+ }
131
+ if (this.ignoreStatuses.includes(error.status)) {
132
+ return false;
133
+ }
134
+ if (error.code && this.ignoreCodes.includes(error.code)) {
135
+ return false;
136
+ }
137
+ if (this.ignoreExceptions.find((exception) => error instanceof exception)) {
138
+ return false;
139
+ }
140
+ return true;
141
+ }
142
+ /**
143
+ * Renders an error to JSON response
144
+ */
145
+ async renderErrorAsJSON(error, ctx) {
146
+ if (this.isDebuggingEnabled(ctx)) {
147
+ const { default: Youch } = await import("youch");
148
+ const json = await new Youch(error, ctx.request.request).toJSON();
149
+ ctx.response.status(error.status).send(json.error);
150
+ return;
151
+ }
152
+ ctx.response.status(error.status).send({ message: error.message });
153
+ }
154
+ /**
155
+ * Renders an error to JSON API response
156
+ */
157
+ async renderErrorAsJSONAPI(error, ctx) {
158
+ if (this.isDebuggingEnabled(ctx)) {
159
+ const { default: Youch } = await import("youch");
160
+ const json = await new Youch(error, ctx.request.request).toJSON();
161
+ ctx.response.status(error.status).send(json.error);
162
+ return;
163
+ }
164
+ ctx.response.status(error.status).send({
165
+ errors: [
166
+ {
167
+ title: error.message,
168
+ code: error.code,
169
+ status: error.status
170
+ }
171
+ ]
172
+ });
173
+ }
174
+ /**
175
+ * Renders an error to HTML response
176
+ */
177
+ async renderErrorAsHTML(error, ctx) {
178
+ if (this.isDebuggingEnabled(ctx)) {
179
+ const { default: Youch } = await import("youch");
180
+ const html = await new Youch(error, ctx.request.request).toHTML({
181
+ cspNonce: "nonce" in ctx.response ? ctx.response.nonce : void 0
182
+ });
183
+ ctx.response.status(error.status).send(html);
184
+ return;
185
+ }
186
+ ctx.response.status(error.status).send(`<p> ${error.message} </p>`);
187
+ }
188
+ /**
189
+ * Renders the validation error message to a JSON
190
+ * response
191
+ */
192
+ async renderValidationErrorAsJSON(error, ctx) {
193
+ ctx.response.status(error.status).send({
194
+ errors: error.messages
195
+ });
196
+ }
197
+ /**
198
+ * Renders the validation error message as per JSON API
199
+ * spec
200
+ */
201
+ async renderValidationErrorAsJSONAPI(error, ctx) {
202
+ ctx.response.status(error.status).send({
203
+ errors: error.messages.map((message) => {
204
+ return {
205
+ title: message.message,
206
+ code: message.rule,
207
+ source: {
208
+ pointer: message.field
209
+ },
210
+ meta: message.meta
211
+ };
212
+ })
213
+ });
214
+ }
215
+ /**
216
+ * Renders the validation error as an HTML string
217
+ */
218
+ async renderValidationErrorAsHTML(error, ctx) {
219
+ ctx.response.status(error.status).type("html").send(
220
+ error.messages.map((message) => {
221
+ return `${message.field} - ${message.message}`;
222
+ }).join("<br />")
223
+ );
224
+ }
225
+ /**
226
+ * Renders the error to response
227
+ */
228
+ renderError(error, ctx) {
229
+ switch (ctx.request.accepts(["html", "application/vnd.api+json", "json"])) {
230
+ case "application/vnd.api+json":
231
+ return this.renderErrorAsJSONAPI(error, ctx);
232
+ case "json":
233
+ return this.renderErrorAsJSON(error, ctx);
234
+ case "html":
235
+ default:
236
+ return this.renderErrorAsHTML(error, ctx);
237
+ }
238
+ }
239
+ /**
240
+ * Renders the validation error to response
241
+ */
242
+ renderValidationError(error, ctx) {
243
+ switch (ctx.request.accepts(["html", "application/vnd.api+json", "json"])) {
244
+ case "application/vnd.api+json":
245
+ return this.renderValidationErrorAsJSONAPI(error, ctx);
246
+ case "json":
247
+ return this.renderValidationErrorAsJSON(error, ctx);
248
+ case "html":
249
+ default:
250
+ return this.renderValidationErrorAsHTML(error, ctx);
251
+ }
252
+ }
253
+ /**
254
+ * Reports an error during an HTTP request
255
+ */
256
+ async report(error, ctx) {
257
+ const httpError = this.#toHttpError(error);
258
+ if (!this.shouldReport(httpError)) {
259
+ return;
260
+ }
261
+ if (typeof httpError.report === "function") {
262
+ httpError.report(httpError, ctx);
263
+ return;
264
+ }
265
+ const level = this.getErrorLogLevel(httpError);
266
+ ctx.logger.log(
267
+ level,
268
+ {
269
+ ...level === "error" || level === "fatal" ? { err: httpError } : {},
270
+ ...this.context(ctx)
271
+ },
272
+ httpError.message
273
+ );
274
+ }
275
+ /**
276
+ * Handles the error during the HTTP request.
277
+ */
278
+ async handle(error, ctx) {
279
+ const httpError = this.#toHttpError(error);
280
+ if (typeof httpError.handle === "function") {
281
+ return httpError.handle(httpError, ctx);
282
+ }
283
+ if (httpError.code === "E_VALIDATION_ERROR" && "messages" in httpError) {
284
+ return this.renderValidationError(httpError, ctx);
285
+ }
286
+ const statusPages = this.#expandStatusPages();
287
+ if (this.renderStatusPages && statusPages[httpError.status]) {
288
+ return statusPages[httpError.status](httpError, ctx);
289
+ }
290
+ return this.renderError(httpError, ctx);
291
+ }
292
+ };
293
+ export {
294
+ BriskRoute,
295
+ CookieClient,
296
+ ExceptionHandler,
297
+ HttpContext,
298
+ Redirect,
299
+ Request,
300
+ Response,
301
+ Route,
302
+ RouteGroup,
303
+ RouteResource,
304
+ Router,
305
+ Server,
306
+ defineConfig,
307
+ exceptions_exports as errors
308
+ };
@@ -1,24 +1,17 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
1
+ import { Logger } from '@adonisjs/logger';
3
2
  import { Emitter } from '@adonisjs/events';
4
- import type { Logger } from '@adonisjs/logger';
5
- import type { Encryption } from '@adonisjs/encryption';
6
- import type { Server as HttpsServer } from 'node:https';
7
- import type { Application } from '@adonisjs/application';
3
+ import { Encryption } from '@adonisjs/encryption';
4
+ import { Server as Server$2 } from 'node:https';
5
+ import { Application } from '@adonisjs/application';
8
6
  import { ContainerResolver } from '@adonisjs/fold';
9
- import type { ServerResponse, IncomingMessage, Server as HttpServer } from 'node:http';
10
- import type { LazyImport } from '../types/base.js';
11
- import type { MiddlewareAsClass } from '../types/middleware.js';
12
- import type { ServerConfig, ErrorHandlerAsAClass, TestingMiddlewarePipeline } from '../types/server.js';
13
- import { Request } from '../request.js';
14
- import { Response } from '../response.js';
15
- import { Router } from '../router/main.js';
16
- import { HttpContext } from '../http_context/main.js';
7
+ import { Server as Server$1, IncomingMessage, ServerResponse } from 'node:http';
8
+ import { S as ServerConfig, M as MiddlewareAsClass, T as TestingMiddlewarePipeline, L as LazyImport, E as ErrorHandlerAsAClass, R as Router, a as Request, b as Response, H as HttpContext } from './main-e5b46c83.js';
9
+
17
10
  /**
18
11
  * The HTTP server implementation to handle incoming requests and respond using the
19
12
  * registered routes.
20
13
  */
21
- export declare class Server {
14
+ declare class Server {
22
15
  #private;
23
16
  /**
24
17
  * Know if async local storage is enabled or not.
@@ -50,12 +43,12 @@ export declare class Server {
50
43
  /**
51
44
  * Set the HTTP server instance used to listen for requests.
52
45
  */
53
- setNodeServer(server: HttpServer | HttpsServer): void;
46
+ setNodeServer(server: Server$1 | Server$2): void;
54
47
  /**
55
48
  * Returns reference to the underlying HTTP server
56
49
  * in use
57
50
  */
58
- getNodeServer(): HttpServer<typeof IncomingMessage, typeof ServerResponse> | HttpsServer<typeof IncomingMessage, typeof ServerResponse> | undefined;
51
+ getNodeServer(): Server$1<typeof IncomingMessage, typeof ServerResponse> | Server$2<typeof IncomingMessage, typeof ServerResponse> | undefined;
59
52
  /**
60
53
  * Returns reference to the router instance used
61
54
  * by the server.
@@ -78,3 +71,5 @@ export declare class Server {
78
71
  */
79
72
  handle(req: IncomingMessage, res: ServerResponse): Promise<any>;
80
73
  }
74
+
75
+ export { Server as S };