@adonisjs/http-server 8.0.0 → 8.1.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.
- package/build/chunk-B2GA45YG.js +35 -0
- package/build/define_config-t7GL92UR.js +5470 -0
- package/build/factories/main.js +163 -5
- package/build/{helpers-C_2HouOe.js → helpers-XD4_pfkD.js} +56 -0
- package/build/helpers-aa47NQc6.js +1426 -0
- package/build/index.js +179 -4
- package/build/src/client/url_builder.d.ts +2 -2
- package/build/src/client/url_builder.js +20 -4
- package/build/src/helpers.js +3 -75
- package/build/src/types/main.js +1 -0
- package/build/src/types/request.d.ts +2 -1
- package/package.json +12 -12
- package/build/define_config-D-kQXU0e.js +0 -2438
- package/build/types-AUwURgIL.js +0 -1
- package/build/utils-BjSHKI3s.js +0 -618
package/build/index.js
CHANGED
|
@@ -1,27 +1,92 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { _ as Qs, a as CookieSerializer, c as HttpRequest, d as Redirect, f as E_CANNOT_LOOKUP_ROUTE, g as errors_exports, h as E_ROUTE_NOT_FOUND, i as HttpResponse, l as CookieParser, m as E_HTTP_REQUEST_ABORTED, n as Server, o as ResponseStatus, p as E_HTTP_EXCEPTION, r as HttpContext, s as Router, t as defineConfig, u as CookieClient } from "./define_config-
|
|
3
|
-
import "./helpers-
|
|
4
|
-
import "./
|
|
1
|
+
import "./chunk-B2GA45YG.js";
|
|
2
|
+
import { _ as Qs, a as CookieSerializer, c as HttpRequest, d as Redirect, f as E_CANNOT_LOOKUP_ROUTE, g as errors_exports, h as E_ROUTE_NOT_FOUND, i as HttpResponse, l as CookieParser, m as E_HTTP_REQUEST_ABORTED, n as Server, o as ResponseStatus, p as E_HTTP_EXCEPTION, r as HttpContext, s as Router, t as defineConfig, u as CookieClient } from "./define_config-t7GL92UR.js";
|
|
3
|
+
import { C as canWriteResponseBody, S as tracing_channels_exports, _ as Route, g as BriskRoute, h as RouteResource, m as RouteGroup, u as parseRange } from "./helpers-aa47NQc6.js";
|
|
4
|
+
import "./helpers-XD4_pfkD.js";
|
|
5
5
|
import Macroable from "@poppinss/macroable";
|
|
6
6
|
import is from "@sindresorhus/is";
|
|
7
|
+
//#region src/exception_handler.ts
|
|
8
|
+
/**
|
|
9
|
+
* The base HTTP exception handler that provides comprehensive error handling capabilities.
|
|
10
|
+
*
|
|
11
|
+
* This class can be inherited to create custom exception handlers for your application.
|
|
12
|
+
* It provides built-in support for:
|
|
13
|
+
*
|
|
14
|
+
* - Self-handling exceptions via their own render/handle methods
|
|
15
|
+
* - Custom status page rendering for different HTTP error codes
|
|
16
|
+
* - Debug-friendly error display during development
|
|
17
|
+
* - Content negotiation for JSON, JSON API, and HTML error responses
|
|
18
|
+
* - Configurable error reporting and logging
|
|
19
|
+
* - Validation error handling with field-specific messages
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* export default class HttpExceptionHandler extends ExceptionHandler {
|
|
24
|
+
* protected debug = app.inDev
|
|
25
|
+
* protected renderStatusPages = app.inProduction
|
|
26
|
+
*
|
|
27
|
+
* protected statusPages = {
|
|
28
|
+
* '404': (error, ctx) => ctx.view.render('errors/404')
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
7
33
|
var ExceptionHandler = class extends Macroable {
|
|
34
|
+
/**
|
|
35
|
+
* Cached expanded status pages mapping individual status codes to their renderers
|
|
36
|
+
* Computed from the statusPages property when first accessed
|
|
37
|
+
*/
|
|
8
38
|
#expandedStatusPages;
|
|
39
|
+
/**
|
|
40
|
+
* Controls whether to include debug information in error responses
|
|
41
|
+
* When enabled, errors include complete stack traces and detailed debugging info
|
|
42
|
+
* Defaults to true in non-production environments
|
|
43
|
+
*/
|
|
9
44
|
debug = process.env.NODE_ENV !== "production";
|
|
45
|
+
/**
|
|
46
|
+
* Controls whether to render custom status pages for unhandled errors
|
|
47
|
+
* When enabled, errors with matching status codes use configured status page renderers
|
|
48
|
+
* Defaults to true in production environments
|
|
49
|
+
*/
|
|
10
50
|
renderStatusPages = process.env.NODE_ENV === "production";
|
|
51
|
+
/**
|
|
52
|
+
* Mapping of HTTP status code ranges to their corresponding page renderers
|
|
53
|
+
* Supports ranges like '400-499' or individual codes like '404'
|
|
54
|
+
*/
|
|
11
55
|
statusPages = {};
|
|
56
|
+
/**
|
|
57
|
+
* Controls whether errors should be reported to logging systems
|
|
58
|
+
* When disabled, errors are handled but not logged or reported
|
|
59
|
+
*/
|
|
12
60
|
reportErrors = true;
|
|
61
|
+
/**
|
|
62
|
+
* Array of exception class constructors to exclude from error reporting
|
|
63
|
+
* These exceptions are handled but not logged or reported to external systems
|
|
64
|
+
*/
|
|
13
65
|
ignoreExceptions = [
|
|
14
66
|
E_HTTP_EXCEPTION,
|
|
15
67
|
E_ROUTE_NOT_FOUND,
|
|
16
68
|
E_CANNOT_LOOKUP_ROUTE,
|
|
17
69
|
E_HTTP_REQUEST_ABORTED
|
|
18
70
|
];
|
|
71
|
+
/**
|
|
72
|
+
* Array of HTTP status codes to exclude from error reporting
|
|
73
|
+
* Errors with these status codes are handled but not logged
|
|
74
|
+
*/
|
|
19
75
|
ignoreStatuses = [
|
|
20
76
|
400,
|
|
21
77
|
422,
|
|
22
78
|
401
|
|
23
79
|
];
|
|
80
|
+
/**
|
|
81
|
+
* Array of custom error codes to exclude from error reporting
|
|
82
|
+
* Errors with these codes are handled but not logged
|
|
83
|
+
*/
|
|
24
84
|
ignoreCodes = [];
|
|
85
|
+
/**
|
|
86
|
+
* Expands status page ranges into individual status code mappings
|
|
87
|
+
* Creates a cached lookup table for faster status page resolution
|
|
88
|
+
* @returns Mapping of status codes to renderers
|
|
89
|
+
*/
|
|
25
90
|
#expandStatusPages() {
|
|
26
91
|
if (!this.#expandedStatusPages) this.#expandedStatusPages = Object.keys(this.statusPages).reduce((result, range) => {
|
|
27
92
|
const renderer = this.statusPages[range];
|
|
@@ -30,24 +95,54 @@ var ExceptionHandler = class extends Macroable {
|
|
|
30
95
|
}, {});
|
|
31
96
|
return this.#expandedStatusPages;
|
|
32
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Normalizes any thrown value into a standardized HttpError object
|
|
100
|
+
* Ensures the error has required properties like message and status
|
|
101
|
+
* @param error - Any thrown value (Error, string, object, etc.)
|
|
102
|
+
* @returns {HttpError} Normalized error object with status and message
|
|
103
|
+
*/
|
|
33
104
|
toHttpError(error) {
|
|
34
105
|
const httpError = is.object(error) ? error : new Error(String(error));
|
|
35
106
|
if (!httpError.message) httpError.message = "Internal server error";
|
|
36
107
|
if (!httpError.status) httpError.status = 500;
|
|
37
108
|
return httpError;
|
|
38
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Provides additional context information for error reporting
|
|
112
|
+
* Includes request ID when available for correlation across logs
|
|
113
|
+
* @param ctx - HTTP context containing request information
|
|
114
|
+
* @returns Additional context data for error reporting
|
|
115
|
+
*/
|
|
39
116
|
context(ctx) {
|
|
40
117
|
const requestId = ctx.request.id();
|
|
41
118
|
return requestId ? { "x-request-id": requestId } : {};
|
|
42
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Determines the appropriate log level based on HTTP status code
|
|
122
|
+
* 5xx errors are logged as 'error', 4xx as 'warn', others as 'info'
|
|
123
|
+
* @param error - HTTP error object with status code
|
|
124
|
+
* @returns {Level} Appropriate logging level for the error
|
|
125
|
+
*/
|
|
43
126
|
getErrorLogLevel(error) {
|
|
44
127
|
if (error.status >= 500) return "error";
|
|
45
128
|
if (error.status >= 400) return "warn";
|
|
46
129
|
return "info";
|
|
47
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Determines whether debug information should be included in error responses
|
|
133
|
+
* Override this method to implement context-specific debug control
|
|
134
|
+
* @param _ - HTTP context (unused in base implementation)
|
|
135
|
+
* @returns {boolean} True if debugging should be enabled
|
|
136
|
+
*/
|
|
48
137
|
isDebuggingEnabled(_) {
|
|
49
138
|
return this.debug;
|
|
50
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* Determines whether an error should be reported to logging systems
|
|
142
|
+
* Checks against ignore lists for exceptions, status codes, and error codes
|
|
143
|
+
* @param error - HTTP error to evaluate for reporting
|
|
144
|
+
* @returns {boolean} True if the error should be reported
|
|
145
|
+
*/
|
|
51
146
|
shouldReport(error) {
|
|
52
147
|
if (this.reportErrors === false) return false;
|
|
53
148
|
if (this.ignoreStatuses.includes(error.status)) return false;
|
|
@@ -55,6 +150,12 @@ var ExceptionHandler = class extends Macroable {
|
|
|
55
150
|
if (this.ignoreExceptions.find((exception) => error instanceof exception)) return false;
|
|
56
151
|
return true;
|
|
57
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* Renders an error as a JSON response
|
|
155
|
+
* In debug mode, includes full stack trace using Youch
|
|
156
|
+
* @param error - HTTP error to render
|
|
157
|
+
* @param ctx - HTTP context for the request
|
|
158
|
+
*/
|
|
58
159
|
async renderErrorAsJSON(error, ctx) {
|
|
59
160
|
if (this.isDebuggingEnabled(ctx)) {
|
|
60
161
|
const { Youch } = await import("youch");
|
|
@@ -64,6 +165,12 @@ var ExceptionHandler = class extends Macroable {
|
|
|
64
165
|
}
|
|
65
166
|
ctx.response.status(error.status).send({ message: error.message });
|
|
66
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* Renders an error as a JSON API compliant response
|
|
170
|
+
* Follows JSON API specification for error objects
|
|
171
|
+
* @param error - HTTP error to render
|
|
172
|
+
* @param ctx - HTTP context for the request
|
|
173
|
+
*/
|
|
67
174
|
async renderErrorAsJSONAPI(error, ctx) {
|
|
68
175
|
if (this.isDebuggingEnabled(ctx)) {
|
|
69
176
|
const { Youch } = await import("youch");
|
|
@@ -77,10 +184,22 @@ var ExceptionHandler = class extends Macroable {
|
|
|
77
184
|
status: error.status
|
|
78
185
|
}] });
|
|
79
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* Renders an error as an HTML response
|
|
189
|
+
* Uses status pages if configured, otherwise shows debug info or simple message
|
|
190
|
+
* @param error - HTTP error to render
|
|
191
|
+
* @param ctx - HTTP context for the request
|
|
192
|
+
*/
|
|
80
193
|
async renderErrorAsHTML(error, ctx) {
|
|
194
|
+
/**
|
|
195
|
+
* Render status page
|
|
196
|
+
*/
|
|
81
197
|
const statusPages = this.#expandStatusPages();
|
|
82
198
|
if (this.renderStatusPages && statusPages[error.status]) {
|
|
83
199
|
const statusPageResponse = await statusPages[error.status](error, ctx);
|
|
200
|
+
/**
|
|
201
|
+
* Use return value and convert it into a response
|
|
202
|
+
*/
|
|
84
203
|
if (canWriteResponseBody(statusPageResponse, ctx)) return ctx.response.safeStatus(error.status).send(statusPageResponse);
|
|
85
204
|
return statusPageResponse;
|
|
86
205
|
}
|
|
@@ -95,9 +214,21 @@ var ExceptionHandler = class extends Macroable {
|
|
|
95
214
|
}
|
|
96
215
|
ctx.response.status(error.status).send(`<p> ${error.message} </p>`);
|
|
97
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* Renders validation error messages as a JSON response
|
|
219
|
+
* Returns errors in a simple format with field-specific messages
|
|
220
|
+
* @param error - Validation error containing messages array
|
|
221
|
+
* @param ctx - HTTP context for the request
|
|
222
|
+
*/
|
|
98
223
|
async renderValidationErrorAsJSON(error, ctx) {
|
|
99
224
|
ctx.response.status(error.status).send({ errors: error.messages });
|
|
100
225
|
}
|
|
226
|
+
/**
|
|
227
|
+
* Renders validation error messages as JSON API compliant response
|
|
228
|
+
* Transforms validation messages to JSON API error object format
|
|
229
|
+
* @param error - Validation error containing messages array
|
|
230
|
+
* @param ctx - HTTP context for the request
|
|
231
|
+
*/
|
|
101
232
|
async renderValidationErrorAsJSONAPI(error, ctx) {
|
|
102
233
|
ctx.response.status(error.status).send({ errors: error.messages.map((message) => {
|
|
103
234
|
return {
|
|
@@ -108,11 +239,23 @@ var ExceptionHandler = class extends Macroable {
|
|
|
108
239
|
};
|
|
109
240
|
}) });
|
|
110
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* Renders validation error messages as an HTML response
|
|
244
|
+
* Creates simple HTML list of field errors separated by line breaks
|
|
245
|
+
* @param error - Validation error containing messages array
|
|
246
|
+
* @param ctx - HTTP context for the request
|
|
247
|
+
*/
|
|
111
248
|
async renderValidationErrorAsHTML(error, ctx) {
|
|
112
249
|
ctx.response.status(error.status).type("html").send(error.messages.map((message) => {
|
|
113
250
|
return `${message.field} - ${message.message}`;
|
|
114
251
|
}).join("<br />"));
|
|
115
252
|
}
|
|
253
|
+
/**
|
|
254
|
+
* Renders an error to the appropriate response format based on content negotiation
|
|
255
|
+
* Supports HTML, JSON API, and JSON formats based on Accept headers
|
|
256
|
+
* @param error - HTTP error to render
|
|
257
|
+
* @param ctx - HTTP context for the request
|
|
258
|
+
*/
|
|
116
259
|
renderError(error, ctx) {
|
|
117
260
|
switch (ctx.request.accepts([
|
|
118
261
|
"html",
|
|
@@ -124,6 +267,12 @@ var ExceptionHandler = class extends Macroable {
|
|
|
124
267
|
default: return this.renderErrorAsHTML(error, ctx);
|
|
125
268
|
}
|
|
126
269
|
}
|
|
270
|
+
/**
|
|
271
|
+
* Renders validation errors to the appropriate response format based on content negotiation
|
|
272
|
+
* Supports HTML, JSON API, and JSON formats for validation error messages
|
|
273
|
+
* @param error - Validation error to render
|
|
274
|
+
* @param ctx - HTTP context for the request
|
|
275
|
+
*/
|
|
127
276
|
renderValidationError(error, ctx) {
|
|
128
277
|
switch (ctx.request.accepts([
|
|
129
278
|
"html",
|
|
@@ -135,6 +284,12 @@ var ExceptionHandler = class extends Macroable {
|
|
|
135
284
|
default: return this.renderValidationErrorAsHTML(error, ctx);
|
|
136
285
|
}
|
|
137
286
|
}
|
|
287
|
+
/**
|
|
288
|
+
* Reports an error to logging systems if reporting is enabled
|
|
289
|
+
* Allows errors to self-report via their own report method if available
|
|
290
|
+
* @param error - Any error object to report
|
|
291
|
+
* @param ctx - HTTP context for additional reporting context
|
|
292
|
+
*/
|
|
138
293
|
async report(error, ctx) {
|
|
139
294
|
const httpError = this.toHttpError(error);
|
|
140
295
|
if (!this.shouldReport(httpError)) return;
|
|
@@ -142,17 +297,37 @@ var ExceptionHandler = class extends Macroable {
|
|
|
142
297
|
httpError.report(httpError, ctx);
|
|
143
298
|
return;
|
|
144
299
|
}
|
|
300
|
+
/**
|
|
301
|
+
* Log the error using the logger
|
|
302
|
+
*/
|
|
145
303
|
const level = this.getErrorLogLevel(httpError);
|
|
146
304
|
ctx.logger.log(level, {
|
|
147
305
|
...level === "error" || level === "fatal" ? { err: httpError } : {},
|
|
148
306
|
...this.context(ctx)
|
|
149
307
|
}, httpError.message);
|
|
150
308
|
}
|
|
309
|
+
/**
|
|
310
|
+
* Handles errors during HTTP request processing
|
|
311
|
+
* Delegates to error's own handle method if available, otherwise renders response
|
|
312
|
+
* @param error - Any error object to handle
|
|
313
|
+
* @param ctx - HTTP context for error handling
|
|
314
|
+
*/
|
|
151
315
|
async handle(error, ctx) {
|
|
152
316
|
const httpError = this.toHttpError(error);
|
|
317
|
+
/**
|
|
318
|
+
* Self handle exception
|
|
319
|
+
*/
|
|
153
320
|
if (typeof httpError.handle === "function") return httpError.handle(httpError, ctx);
|
|
321
|
+
/**
|
|
322
|
+
* Handle validation error using the validation error
|
|
323
|
+
* renderers
|
|
324
|
+
*/
|
|
154
325
|
if (httpError.code === "E_VALIDATION_ERROR" && "messages" in httpError) return this.renderValidationError(httpError, ctx);
|
|
326
|
+
/**
|
|
327
|
+
* Use the format renderers.
|
|
328
|
+
*/
|
|
155
329
|
return this.renderError(httpError, ctx);
|
|
156
330
|
}
|
|
157
331
|
};
|
|
332
|
+
//#endregion
|
|
158
333
|
export { BriskRoute, CookieClient, CookieParser, CookieSerializer, ExceptionHandler, HttpContext, HttpRequest, HttpResponse, Qs, Redirect, ResponseStatus, Route, RouteGroup, RouteResource, Router, Server, defineConfig, errors_exports as errors, tracing_channels_exports as tracingChannels };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createURL, findRoute } from './helpers.ts';
|
|
2
|
-
import { type UrlFor, type LookupList, type ClientRouteJSON } from './types.ts';
|
|
2
|
+
import { type UrlFor, type LookupList, type URLOptions, type ClientRouteJSON } from './types.ts';
|
|
3
3
|
export * from './types.ts';
|
|
4
4
|
export { createURL, findRoute };
|
|
5
5
|
/**
|
|
@@ -12,4 +12,4 @@ export declare function createUrlBuilder<Routes extends LookupList>(routesLoader
|
|
|
12
12
|
[domain: string]: ClientRouteJSON[];
|
|
13
13
|
} | (() => {
|
|
14
14
|
[domain: string]: ClientRouteJSON[];
|
|
15
|
-
}), searchParamsStringifier: (qs: Record<string, any>) => string): UrlFor<Routes>;
|
|
15
|
+
}), searchParamsStringifier: (qs: Record<string, any>) => string, defaultOptions?: URLOptions): UrlFor<Routes>;
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import "../../
|
|
3
|
-
|
|
1
|
+
import "../../chunk-B2GA45YG.js";
|
|
2
|
+
import { n as findRoute, t as createURL } from "../../helpers-XD4_pfkD.js";
|
|
3
|
+
//#region src/client/url_builder.ts
|
|
4
|
+
/**
|
|
5
|
+
* Creates the URLBuilder helper
|
|
6
|
+
* @param router - The router instance
|
|
7
|
+
* @param searchParamsStringifier - Function to stringify query string parameters
|
|
8
|
+
* @returns URL builder function for creating URLs
|
|
9
|
+
*/
|
|
10
|
+
function createUrlBuilder(routesLoader, searchParamsStringifier, defaultOptions) {
|
|
4
11
|
let domainsList;
|
|
5
12
|
let domainsRoutes;
|
|
6
13
|
function createUrlForRoute(identifier, params, options, method) {
|
|
@@ -16,8 +23,16 @@ function createUrlBuilder(routesLoader, searchParamsStringifier) {
|
|
|
16
23
|
if (method) throw new Error(`Cannot lookup route "${routeIdentifier}" for method "${method}"`);
|
|
17
24
|
throw new Error(`Cannot lookup route "${routeIdentifier}"`);
|
|
18
25
|
}
|
|
19
|
-
|
|
26
|
+
const mergedOptions = defaultOptions || options ? {
|
|
27
|
+
...defaultOptions,
|
|
28
|
+
...options
|
|
29
|
+
} : void 0;
|
|
30
|
+
return createURL(route.name ?? route.pattern, route.tokens, searchParamsStringifier, params, mergedOptions);
|
|
20
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* The urlFor helper is used to make URLs for pre-existing known routes. You can
|
|
34
|
+
* make a URL using the route name or the route pattern.
|
|
35
|
+
*/
|
|
21
36
|
const urlFor = function route(...[identifier, params, options]) {
|
|
22
37
|
return createUrlForRoute(identifier, params, options);
|
|
23
38
|
};
|
|
@@ -112,4 +127,5 @@ function createUrlBuilder(routesLoader, searchParamsStringifier) {
|
|
|
112
127
|
};
|
|
113
128
|
return urlFor;
|
|
114
129
|
}
|
|
130
|
+
//#endregion
|
|
115
131
|
export { createURL, createUrlBuilder, findRoute };
|
package/build/src/helpers.js
CHANGED
|
@@ -1,76 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { t as
|
|
3
|
-
import {
|
|
4
|
-
import matchit from "@poppinss/matchit";
|
|
5
|
-
import string from "@poppinss/utils/string";
|
|
6
|
-
import { parseBindingReference } from "@adonisjs/fold";
|
|
7
|
-
import encodeUrl from "encodeurl";
|
|
8
|
-
import mime from "mime-types";
|
|
9
|
-
function parseRoute(pattern, matchers) {
|
|
10
|
-
return matchit.parse(pattern, matchers);
|
|
11
|
-
}
|
|
12
|
-
function createSignedURL(identifier, tokens, searchParamsStringifier, encryption, params, options) {
|
|
13
|
-
const signature = encryption.getMessageVerifier().sign(createURL(identifier, tokens, searchParamsStringifier, params, {
|
|
14
|
-
...options,
|
|
15
|
-
prefixUrl: void 0
|
|
16
|
-
}), options?.expiresIn, options?.purpose);
|
|
17
|
-
return createURL(identifier, tokens, searchParamsStringifier, params, {
|
|
18
|
-
...options,
|
|
19
|
-
qs: {
|
|
20
|
-
...options?.qs,
|
|
21
|
-
signature
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
function matchRoute(url, patterns) {
|
|
26
|
-
const tokensBucket = patterns.map((pattern) => parseRoute(pattern));
|
|
27
|
-
const match = matchit.match(url, tokensBucket);
|
|
28
|
-
if (!match.length) return null;
|
|
29
|
-
return matchit.exec(url, match);
|
|
30
|
-
}
|
|
31
|
-
function serializeCookie(key, value, options) {
|
|
32
|
-
let expires;
|
|
33
|
-
let maxAge;
|
|
34
|
-
if (options) {
|
|
35
|
-
expires = typeof options.expires === "function" ? options.expires() : options.expires;
|
|
36
|
-
maxAge = options.maxAge ? string.seconds.parse(options.maxAge) : void 0;
|
|
37
|
-
}
|
|
38
|
-
return serialize(key, value, {
|
|
39
|
-
...options,
|
|
40
|
-
maxAge,
|
|
41
|
-
expires
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
async function middlewareInfo(middleware) {
|
|
45
|
-
if (typeof middleware === "function") return {
|
|
46
|
-
type: "closure",
|
|
47
|
-
name: middleware.name || "closure"
|
|
48
|
-
};
|
|
49
|
-
if ("args" in middleware) return {
|
|
50
|
-
type: "named",
|
|
51
|
-
name: middleware.name,
|
|
52
|
-
args: middleware.args,
|
|
53
|
-
...await parseBindingReference([middleware.reference])
|
|
54
|
-
};
|
|
55
|
-
return {
|
|
56
|
-
type: "global",
|
|
57
|
-
name: middleware.name,
|
|
58
|
-
...await parseBindingReference([middleware.reference])
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
async function routeInfo(route) {
|
|
62
|
-
return "reference" in route.handler ? {
|
|
63
|
-
type: "controller",
|
|
64
|
-
...await parseBindingReference(route.handler.reference)
|
|
65
|
-
} : {
|
|
66
|
-
type: "closure",
|
|
67
|
-
name: route.handler.name || "closure",
|
|
68
|
-
args: "listArgs" in route.handler ? String(route.handler.listArgs) : void 0
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
function appendQueryString(uri, queryString, qsParser) {
|
|
72
|
-
const { query, pathname } = safeDecodeURI(uri, false);
|
|
73
|
-
const mergedQueryString = qsParser.stringify(Object.assign(qsParser.parse(query), queryString));
|
|
74
|
-
return mergedQueryString ? `${pathname}?${mergedQueryString}` : pathname;
|
|
75
|
-
}
|
|
1
|
+
import "../chunk-B2GA45YG.js";
|
|
2
|
+
import { a as middlewareInfo, c as routeInfo, i as matchRoute, l as serializeCookie, n as createSignedURL, o as mime, r as encodeUrl, s as parseRoute, t as appendQueryString } from "../helpers-aa47NQc6.js";
|
|
3
|
+
import { t as createURL } from "../helpers-XD4_pfkD.js";
|
|
76
4
|
export { appendQueryString, createSignedURL, createURL, encodeUrl, matchRoute, middlewareInfo, mime, parseRoute, routeInfo, serializeCookie };
|
package/build/src/types/main.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type HttpRequest } from '../request.ts';
|
|
1
2
|
/**
|
|
2
3
|
* Configuration options for HTTP request handling and processing
|
|
3
4
|
*/
|
|
@@ -32,7 +33,7 @@ export type RequestConfig = {
|
|
|
32
33
|
/**
|
|
33
34
|
* A custom implementation to get the request ip address
|
|
34
35
|
*/
|
|
35
|
-
getIp?: (request:
|
|
36
|
+
getIp?: (request: HttpRequest, originalFn: () => string) => string;
|
|
36
37
|
/**
|
|
37
38
|
* A callback function to trust proxy ip addresses. You must use
|
|
38
39
|
* the `proxy-addr` package to compute this value.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/http-server",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.1.0",
|
|
4
4
|
"description": "AdonisJS HTTP server with support packed with Routing and Cookies",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -47,18 +47,18 @@
|
|
|
47
47
|
"@adonisjs/eslint-config": "^3.0.0",
|
|
48
48
|
"@adonisjs/events": "^10.1.0",
|
|
49
49
|
"@adonisjs/fold": "^11.0.0",
|
|
50
|
-
"@adonisjs/logger": "^7.1.
|
|
50
|
+
"@adonisjs/logger": "^7.1.1",
|
|
51
51
|
"@adonisjs/prettier-config": "^1.4.5",
|
|
52
52
|
"@adonisjs/tsconfig": "^2.0.0",
|
|
53
53
|
"@boringnode/encryption": "^1.0.0",
|
|
54
|
-
"@fastify/middie": "^9.1
|
|
54
|
+
"@fastify/middie": "^9.3.1",
|
|
55
55
|
"@japa/assert": "^4.2.0",
|
|
56
56
|
"@japa/expect-type": "^2.0.4",
|
|
57
57
|
"@japa/file-system": "^3.0.0",
|
|
58
58
|
"@japa/runner": "^5.3.0",
|
|
59
59
|
"@japa/snapshot": "^2.0.10",
|
|
60
60
|
"@poppinss/ts-exec": "^1.4.4",
|
|
61
|
-
"@release-it/conventional-changelog": "^10.0.
|
|
61
|
+
"@release-it/conventional-changelog": "^10.0.6",
|
|
62
62
|
"@types/accepts": "^1.3.7",
|
|
63
63
|
"@types/content-disposition": "^0.5.9",
|
|
64
64
|
"@types/destroy": "^1.0.3",
|
|
@@ -67,11 +67,11 @@
|
|
|
67
67
|
"@types/fresh": "^0.5.3",
|
|
68
68
|
"@types/fs-extra": "^11.0.4",
|
|
69
69
|
"@types/mime-types": "^3.0.1",
|
|
70
|
-
"@types/node": "^25.
|
|
70
|
+
"@types/node": "^25.5.0",
|
|
71
71
|
"@types/on-finished": "^2.3.5",
|
|
72
72
|
"@types/pem": "^1.14.4",
|
|
73
73
|
"@types/proxy-addr": "^2.0.3",
|
|
74
|
-
"@types/supertest": "^
|
|
74
|
+
"@types/supertest": "^7.2.0",
|
|
75
75
|
"@types/type-is": "^1.6.7",
|
|
76
76
|
"@types/vary": "^1.1.3",
|
|
77
77
|
"@vinejs/vine": "^4.3.0",
|
|
@@ -79,9 +79,9 @@
|
|
|
79
79
|
"autocannon": "^8.0.0",
|
|
80
80
|
"c8": "^11.0.0",
|
|
81
81
|
"cross-env": "^10.1.0",
|
|
82
|
-
"eslint": "^10.0.
|
|
83
|
-
"fastify": "^5.
|
|
84
|
-
"fs-extra": "^11.3.
|
|
82
|
+
"eslint": "^10.0.3",
|
|
83
|
+
"fastify": "^5.8.2",
|
|
84
|
+
"fs-extra": "^11.3.4",
|
|
85
85
|
"get-port": "^7.1.0",
|
|
86
86
|
"http-status-codes": "^2.3.0",
|
|
87
87
|
"pem": "^1.14.8",
|
|
@@ -89,17 +89,17 @@
|
|
|
89
89
|
"reflect-metadata": "^0.2.2",
|
|
90
90
|
"release-it": "^19.2.4",
|
|
91
91
|
"supertest": "^7.2.2",
|
|
92
|
-
"tsdown": "^0.
|
|
92
|
+
"tsdown": "^0.21.4",
|
|
93
93
|
"typedoc": "^0.28.17",
|
|
94
94
|
"typescript": "^5.9.3",
|
|
95
95
|
"youch": "^4.1.0"
|
|
96
96
|
},
|
|
97
97
|
"dependencies": {
|
|
98
|
-
"@poppinss/macroable": "^1.1.
|
|
98
|
+
"@poppinss/macroable": "^1.1.2",
|
|
99
99
|
"@poppinss/matchit": "^3.2.0",
|
|
100
100
|
"@poppinss/middleware": "^3.2.7",
|
|
101
101
|
"@poppinss/qs": "^6.15.0",
|
|
102
|
-
"@poppinss/utils": "^7.0.
|
|
102
|
+
"@poppinss/utils": "^7.0.1",
|
|
103
103
|
"@sindresorhus/is": "^7.2.0",
|
|
104
104
|
"content-disposition": "^1.0.1",
|
|
105
105
|
"cookie-es": "^2.0.0",
|