@adonisjs/http-server 6.4.3-0 → 6.6.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.
- package/LICENSE.md +1 -1
- package/build/{test_factories → factories}/http_context.d.ts +0 -0
- package/build/{test_factories → factories}/http_context.js +0 -0
- package/build/factories/main.d.ts +6 -0
- package/build/factories/main.js +6 -0
- package/build/{test_factories → factories}/qs_parser_factory.d.ts +0 -0
- package/build/{test_factories → factories}/qs_parser_factory.js +0 -0
- package/build/{test_factories → factories}/request.d.ts +0 -0
- package/build/{test_factories → factories}/request.js +1 -1
- package/build/{test_factories → factories}/response.d.ts +0 -0
- package/build/{test_factories → factories}/response.js +0 -0
- package/build/{test_factories → factories}/router.d.ts +0 -0
- package/build/{test_factories → factories}/router.js +0 -0
- package/build/{test_factories → factories}/server_factory.d.ts +0 -0
- package/build/{test_factories → factories}/server_factory.js +0 -0
- package/build/index.d.ts +2 -1
- package/build/index.js +2 -1
- package/build/src/exception_handler.d.ts +28 -0
- package/build/src/exception_handler.js +148 -0
- package/build/src/{exceptions/main.d.ts → exceptions.d.ts} +1 -1
- package/build/src/{exceptions/main.js → exceptions.js} +0 -0
- package/build/src/helpers.d.ts +1 -0
- package/build/src/helpers.js +21 -0
- package/build/src/request.d.ts +4 -0
- package/build/src/request.js +7 -2
- package/build/src/response.d.ts +6 -0
- package/build/src/response.js +17 -2
- package/build/src/router/lookup_store/route_finder.js +1 -1
- package/build/src/server/factories/final_handler.js +1 -1
- package/build/src/server/main.js +5 -1
- package/build/src/types/server.d.ts +14 -0
- package/package.json +18 -17
package/LICENSE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# The MIT License
|
|
2
2
|
|
|
3
|
-
Copyright
|
|
3
|
+
Copyright (c) 2023 AdonisJS Framework
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
6
|
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { HttpContextFactory } from './http_context.js';
|
|
2
|
+
export { QsParserFactory } from './qs_parser_factory.js';
|
|
3
|
+
export { RequestFactory } from './request.js';
|
|
4
|
+
export { ResponseFactory } from './response.js';
|
|
5
|
+
export { RouterFactory } from './router.js';
|
|
6
|
+
export { ServerFactory } from './server_factory.js';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { HttpContextFactory } from './http_context.js';
|
|
2
|
+
export { QsParserFactory } from './qs_parser_factory.js';
|
|
3
|
+
export { RequestFactory } from './request.js';
|
|
4
|
+
export { ResponseFactory } from './response.js';
|
|
5
|
+
export { RouterFactory } from './router.js';
|
|
6
|
+
export { ServerFactory } from './server_factory.js';
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/build/index.d.ts
CHANGED
|
@@ -9,4 +9,5 @@ export { defineConfig } from './src/define_config.js';
|
|
|
9
9
|
export { RouteResource } from './src/router/resource.js';
|
|
10
10
|
export { BriskRoute } from './src/router/brisk.js';
|
|
11
11
|
export { HttpContext } from './src/http_context/main.js';
|
|
12
|
-
export * as errors from './src/exceptions
|
|
12
|
+
export * as errors from './src/exceptions.js';
|
|
13
|
+
export { HttpExceptionHandler } from './src/exception_handler.js';
|
package/build/index.js
CHANGED
|
@@ -9,4 +9,5 @@ export { defineConfig } from './src/define_config.js';
|
|
|
9
9
|
export { RouteResource } from './src/router/resource.js';
|
|
10
10
|
export { BriskRoute } from './src/router/brisk.js';
|
|
11
11
|
export { HttpContext } from './src/http_context/main.js';
|
|
12
|
-
export * as errors from './src/exceptions
|
|
12
|
+
export * as errors from './src/exceptions.js';
|
|
13
|
+
export { HttpExceptionHandler } from './src/exception_handler.js';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Logger } from '@adonisjs/logger';
|
|
2
|
+
import type { Level } from '@adonisjs/logger/types';
|
|
3
|
+
import type { HttpContext } from './http_context/main.js';
|
|
4
|
+
import type { HttpError, StatusPageRange, StatusPageRenderer } from './types/server.js';
|
|
5
|
+
export declare class HttpExceptionHandler {
|
|
6
|
+
#private;
|
|
7
|
+
protected logger: Logger;
|
|
8
|
+
protected debug: boolean;
|
|
9
|
+
protected renderStatusPages: boolean;
|
|
10
|
+
protected statusPages: Record<StatusPageRange, StatusPageRenderer>;
|
|
11
|
+
protected renderers: {
|
|
12
|
+
html: (error: HttpError, ctx: HttpContext) => Promise<void>;
|
|
13
|
+
json: (error: HttpError, ctx: HttpContext) => Promise<void>;
|
|
14
|
+
json_api: (error: HttpError, ctx: HttpContext) => Promise<void>;
|
|
15
|
+
};
|
|
16
|
+
protected reportErrors: boolean;
|
|
17
|
+
protected ignoreExceptions: any[];
|
|
18
|
+
protected ignoreStatuses: number[];
|
|
19
|
+
protected ignoreCodes: string[];
|
|
20
|
+
constructor(logger: Logger);
|
|
21
|
+
protected context(ctx: HttpContext): any;
|
|
22
|
+
protected getResponseFormat(ctx: HttpContext): 'html' | 'json' | 'json_api';
|
|
23
|
+
protected getErrorLogLevel(error: HttpError): Level;
|
|
24
|
+
protected isDebuggingEnabled(_: HttpContext): boolean;
|
|
25
|
+
protected shouldReport(error: HttpError): boolean;
|
|
26
|
+
report(error: unknown, ctx: HttpContext): Promise<void>;
|
|
27
|
+
handle(error: unknown, ctx: HttpContext): Promise<any>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import is from '@sindresorhus/is';
|
|
2
|
+
import { parseRange } from './helpers.js';
|
|
3
|
+
import * as errors from './exceptions.js';
|
|
4
|
+
export class HttpExceptionHandler {
|
|
5
|
+
logger;
|
|
6
|
+
debug = process.env.NODE_ENV !== 'production';
|
|
7
|
+
renderStatusPages = process.env.NODE_ENV === 'production';
|
|
8
|
+
statusPages = {};
|
|
9
|
+
#expandedStatusPages;
|
|
10
|
+
renderers = {
|
|
11
|
+
html: async (error, ctx) => {
|
|
12
|
+
if (this.isDebuggingEnabled(ctx)) {
|
|
13
|
+
const { default: Youch } = await import('youch');
|
|
14
|
+
const html = await new Youch(error, ctx.request.request).toHTML();
|
|
15
|
+
ctx.response.status(error.status).send(html);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
ctx.response.status(error.status).send(`<p> ${error.message} </p>`);
|
|
19
|
+
},
|
|
20
|
+
json: async (error, ctx) => {
|
|
21
|
+
if (this.isDebuggingEnabled(ctx)) {
|
|
22
|
+
const { default: Youch } = await import('youch');
|
|
23
|
+
const json = await new Youch(error, ctx.request.request).toJSON();
|
|
24
|
+
ctx.response.status(error.status).send(json.error);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
ctx.response.status(error.status).send({ message: error.message });
|
|
28
|
+
},
|
|
29
|
+
json_api: async (error, ctx) => {
|
|
30
|
+
if (this.isDebuggingEnabled(ctx)) {
|
|
31
|
+
const { default: Youch } = await import('youch');
|
|
32
|
+
const json = await new Youch(error, ctx.request.request).toJSON();
|
|
33
|
+
ctx.response.status(error.status).send(json.error);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
ctx.response.status(error.status).send({
|
|
37
|
+
errors: [
|
|
38
|
+
{
|
|
39
|
+
title: error.message,
|
|
40
|
+
code: error.code,
|
|
41
|
+
status: error.status,
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
reportErrors = true;
|
|
48
|
+
ignoreExceptions = [
|
|
49
|
+
errors.E_HTTP_EXCEPTION,
|
|
50
|
+
errors.E_ROUTE_NOT_FOUND,
|
|
51
|
+
errors.E_CANNOT_LOOKUP_ROUTE,
|
|
52
|
+
errors.E_HTTP_REQUEST_ABORTED,
|
|
53
|
+
];
|
|
54
|
+
ignoreStatuses = [400, 422, 401];
|
|
55
|
+
ignoreCodes = [];
|
|
56
|
+
constructor(logger) {
|
|
57
|
+
this.logger = logger;
|
|
58
|
+
}
|
|
59
|
+
#expandStatusPages() {
|
|
60
|
+
if (!this.#expandedStatusPages) {
|
|
61
|
+
this.#expandedStatusPages = Object.keys(this.statusPages).reduce((result, range) => {
|
|
62
|
+
const renderer = this.statusPages[range];
|
|
63
|
+
result = Object.assign(result, parseRange(range, renderer));
|
|
64
|
+
return result;
|
|
65
|
+
}, {});
|
|
66
|
+
}
|
|
67
|
+
return this.#expandedStatusPages;
|
|
68
|
+
}
|
|
69
|
+
#toHttpError(error) {
|
|
70
|
+
const httpError = is.object(error) ? error : new Error(String(error));
|
|
71
|
+
httpError.message = httpError.message || 'Internal server error';
|
|
72
|
+
httpError.status = httpError.status || 500;
|
|
73
|
+
return httpError;
|
|
74
|
+
}
|
|
75
|
+
context(ctx) {
|
|
76
|
+
const requestId = ctx.request.id();
|
|
77
|
+
return requestId
|
|
78
|
+
? {
|
|
79
|
+
'x-request-id': requestId,
|
|
80
|
+
}
|
|
81
|
+
: {};
|
|
82
|
+
}
|
|
83
|
+
getResponseFormat(ctx) {
|
|
84
|
+
switch (ctx.request.accepts(['html', 'application/vnd.api+json', 'json'])) {
|
|
85
|
+
case 'application/vnd.api+json':
|
|
86
|
+
return 'json_api';
|
|
87
|
+
case 'json':
|
|
88
|
+
return 'json';
|
|
89
|
+
case 'html':
|
|
90
|
+
default:
|
|
91
|
+
return 'html';
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
getErrorLogLevel(error) {
|
|
95
|
+
if (error.status >= 500) {
|
|
96
|
+
return 'error';
|
|
97
|
+
}
|
|
98
|
+
if (error.status >= 400) {
|
|
99
|
+
return 'warn';
|
|
100
|
+
}
|
|
101
|
+
return 'info';
|
|
102
|
+
}
|
|
103
|
+
isDebuggingEnabled(_) {
|
|
104
|
+
return this.debug;
|
|
105
|
+
}
|
|
106
|
+
shouldReport(error) {
|
|
107
|
+
if (this.reportErrors === false) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
if (this.ignoreStatuses.includes(error.status)) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
if (error.code && this.ignoreCodes.includes(error.code)) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
if (this.ignoreExceptions.find((exception) => error instanceof exception)) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
async report(error, ctx) {
|
|
122
|
+
const httpError = this.#toHttpError(error);
|
|
123
|
+
if (!this.shouldReport(httpError)) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (typeof httpError.report === 'function') {
|
|
127
|
+
httpError.report(httpError, ctx);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const level = this.getErrorLogLevel(httpError);
|
|
131
|
+
this.logger.log(level, {
|
|
132
|
+
...(level === 'error' || level === 'fatal' ? { err: httpError } : {}),
|
|
133
|
+
...this.context(ctx),
|
|
134
|
+
}, httpError.message);
|
|
135
|
+
}
|
|
136
|
+
async handle(error, ctx) {
|
|
137
|
+
const httpError = this.#toHttpError(error);
|
|
138
|
+
if (typeof httpError.handle === 'function') {
|
|
139
|
+
return httpError.handle(httpError, ctx);
|
|
140
|
+
}
|
|
141
|
+
const statusPages = this.#expandStatusPages();
|
|
142
|
+
if (this.renderStatusPages && statusPages[httpError.status]) {
|
|
143
|
+
return statusPages[httpError.status](httpError, ctx);
|
|
144
|
+
}
|
|
145
|
+
const responseFormat = this.getResponseFormat(ctx);
|
|
146
|
+
return this.renderers[responseFormat](httpError, ctx);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
import { Exception } from '@poppinss/utils';
|
|
3
|
-
import type { HttpContext } from '
|
|
3
|
+
import type { HttpContext } from './http_context/main.js';
|
|
4
4
|
export declare const E_ROUTE_NOT_FOUND: new (args: [method: string, url: string], options?: ErrorOptions | undefined) => Exception;
|
|
5
5
|
export declare const E_CANNOT_LOOKUP_ROUTE: new (args: [routeIdentifier: string], options?: ErrorOptions | undefined) => Exception;
|
|
6
6
|
export declare const E_HTTP_EXCEPTION: {
|
|
File without changes
|
package/build/src/helpers.d.ts
CHANGED
|
@@ -6,3 +6,4 @@ import { RouteResource } from './router/resource.js';
|
|
|
6
6
|
export declare function dropSlash(input: string): string;
|
|
7
7
|
export declare function toRoutesJSON(routes: (RouteGroup | Route | RouteResource | BriskRoute)[]): RouteJSON[];
|
|
8
8
|
export declare function trustProxy(remoteAddress: string, proxyFn: (addr: string, distance: number) => boolean): boolean;
|
|
9
|
+
export declare function parseRange<T>(range: string, value: T): Record<number, T>;
|
package/build/src/helpers.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Cache from 'tmp-cache';
|
|
2
|
+
import { InvalidArgumentsException } from '@poppinss/utils';
|
|
2
3
|
import { BriskRoute } from './router/brisk.js';
|
|
3
4
|
import { RouteGroup } from './router/group.js';
|
|
4
5
|
import { RouteResource } from './router/resource.js';
|
|
@@ -39,3 +40,23 @@ export function trustProxy(remoteAddress, proxyFn) {
|
|
|
39
40
|
proxyCache.set(remoteAddress, result);
|
|
40
41
|
return result;
|
|
41
42
|
}
|
|
43
|
+
export function parseRange(range, value) {
|
|
44
|
+
const parts = range.split('..');
|
|
45
|
+
const min = Number(parts[0]);
|
|
46
|
+
const max = Number(parts[1]);
|
|
47
|
+
if (Number.isNaN(min) || Number.isNaN(max)) {
|
|
48
|
+
return {};
|
|
49
|
+
}
|
|
50
|
+
if (min === max) {
|
|
51
|
+
return {
|
|
52
|
+
[min]: value,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
if (max < min) {
|
|
56
|
+
throw new InvalidArgumentsException(`Invalid range "${range}"`);
|
|
57
|
+
}
|
|
58
|
+
return [...Array(max - min + 1).keys()].reduce((result, step) => {
|
|
59
|
+
result[min + step] = value;
|
|
60
|
+
return result;
|
|
61
|
+
}, {});
|
|
62
|
+
}
|
package/build/src/request.d.ts
CHANGED
|
@@ -62,6 +62,10 @@ export declare class Request extends Macroable {
|
|
|
62
62
|
cookiesList(): Record<string, any>;
|
|
63
63
|
cookie(key: string, defaultValue?: string): any;
|
|
64
64
|
encryptedCookie(key: string, defaultValue?: string): any;
|
|
65
|
+
plainCookie(key: string, options?: {
|
|
66
|
+
defaultValue?: string;
|
|
67
|
+
encoded?: boolean;
|
|
68
|
+
}): any;
|
|
65
69
|
plainCookie(key: string, defaultValue?: string, encoded?: boolean): any;
|
|
66
70
|
hasValidSignature(purpose?: string): boolean;
|
|
67
71
|
toJSON(): {
|
package/build/src/request.js
CHANGED
|
@@ -3,6 +3,7 @@ import fresh from 'fresh';
|
|
|
3
3
|
import typeIs from 'type-is';
|
|
4
4
|
import accepts from 'accepts';
|
|
5
5
|
import { isIP } from 'node:net';
|
|
6
|
+
import is from '@sindresorhus/is';
|
|
6
7
|
import proxyaddr from 'proxy-addr';
|
|
7
8
|
import lodash from '@poppinss/utils/lodash';
|
|
8
9
|
import { safeEqual } from '@poppinss/utils';
|
|
@@ -278,9 +279,13 @@ export class Request extends Macroable {
|
|
|
278
279
|
this.#initiateCookieParser();
|
|
279
280
|
return this.#cookieParser.decrypt(key) || defaultValue;
|
|
280
281
|
}
|
|
281
|
-
plainCookie(key,
|
|
282
|
+
plainCookie(key, defaultValueOrOptions, encoded) {
|
|
282
283
|
this.#initiateCookieParser();
|
|
283
|
-
|
|
284
|
+
if (is.object(defaultValueOrOptions)) {
|
|
285
|
+
return (this.#cookieParser.decode(key, defaultValueOrOptions?.encoded) ||
|
|
286
|
+
defaultValueOrOptions.defaultValue);
|
|
287
|
+
}
|
|
288
|
+
return this.#cookieParser.decode(key, encoded) || defaultValueOrOptions;
|
|
284
289
|
}
|
|
285
290
|
hasValidSignature(purpose) {
|
|
286
291
|
const { signature, ...rest } = this.qs();
|
package/build/src/response.d.ts
CHANGED
|
@@ -15,7 +15,13 @@ export declare class Response extends Macroable {
|
|
|
15
15
|
get hasLazyBody(): boolean;
|
|
16
16
|
get hasContent(): boolean;
|
|
17
17
|
get hasStream(): boolean;
|
|
18
|
+
get hasFileToStream(): boolean;
|
|
18
19
|
get content(): [any, boolean, (string | undefined)?] | undefined;
|
|
20
|
+
get outgoingStream(): ResponseStream | undefined;
|
|
21
|
+
get fileToStream(): {
|
|
22
|
+
path: string;
|
|
23
|
+
generateEtag: boolean;
|
|
24
|
+
} | undefined;
|
|
19
25
|
lazyBody: Partial<{
|
|
20
26
|
content: [any, boolean, string?];
|
|
21
27
|
stream: [ResponseStream, ((error: NodeJS.ErrnoException) => [string, number?])?];
|
package/build/src/response.js
CHANGED
|
@@ -13,7 +13,7 @@ import { RuntimeException } from '@poppinss/utils';
|
|
|
13
13
|
import contentDisposition from 'content-disposition';
|
|
14
14
|
import { Redirect } from './redirect.js';
|
|
15
15
|
import { CookieSerializer } from './cookies/serializer.js';
|
|
16
|
-
import { E_HTTP_REQUEST_ABORTED } from './exceptions
|
|
16
|
+
import { E_HTTP_REQUEST_ABORTED } from './exceptions.js';
|
|
17
17
|
const statFn = promisify(stat);
|
|
18
18
|
const CACHEABLE_HTTP_METHODS = ['GET', 'HEAD'];
|
|
19
19
|
export class Response extends Macroable {
|
|
@@ -32,11 +32,25 @@ export class Response extends Macroable {
|
|
|
32
32
|
return !!this.lazyBody.content;
|
|
33
33
|
}
|
|
34
34
|
get hasStream() {
|
|
35
|
-
return !!
|
|
35
|
+
return !!this.lazyBody.stream;
|
|
36
|
+
}
|
|
37
|
+
get hasFileToStream() {
|
|
38
|
+
return !!this.lazyBody.fileToStream;
|
|
36
39
|
}
|
|
37
40
|
get content() {
|
|
38
41
|
return this.lazyBody.content;
|
|
39
42
|
}
|
|
43
|
+
get outgoingStream() {
|
|
44
|
+
return this.lazyBody.stream?.[0];
|
|
45
|
+
}
|
|
46
|
+
get fileToStream() {
|
|
47
|
+
return this.lazyBody.fileToStream
|
|
48
|
+
? {
|
|
49
|
+
path: this.lazyBody.fileToStream[0],
|
|
50
|
+
generateEtag: this.lazyBody.fileToStream[1],
|
|
51
|
+
}
|
|
52
|
+
: undefined;
|
|
53
|
+
}
|
|
40
54
|
lazyBody = {};
|
|
41
55
|
ctx;
|
|
42
56
|
constructor(request, response, encryption, config, router, qs) {
|
|
@@ -267,6 +281,7 @@ export class Response extends Macroable {
|
|
|
267
281
|
}
|
|
268
282
|
removeHeader(key) {
|
|
269
283
|
key = key.toLowerCase();
|
|
284
|
+
this.response.removeHeader(key);
|
|
270
285
|
if (this.#headers[key]) {
|
|
271
286
|
delete this.#headers[key.toLowerCase()];
|
|
272
287
|
}
|
package/build/src/server/main.js
CHANGED
|
@@ -13,6 +13,7 @@ import { asyncLocalStorage } from '../http_context/local_storage.js';
|
|
|
13
13
|
import { middlewareHandler } from './factories/middleware_handler.js';
|
|
14
14
|
export class Server {
|
|
15
15
|
#defaultErrorHandler = {
|
|
16
|
+
report() { },
|
|
16
17
|
handle(error, ctx) {
|
|
17
18
|
ctx.response.status(error.status || 500).send(error.message || 'Internal server error');
|
|
18
19
|
},
|
|
@@ -60,7 +61,10 @@ export class Server {
|
|
|
60
61
|
}
|
|
61
62
|
#handleRequest(ctx, resolver) {
|
|
62
63
|
return this.#serverMiddlewareStack.runner()
|
|
63
|
-
.errorHandler((error) =>
|
|
64
|
+
.errorHandler((error) => {
|
|
65
|
+
this.#resolvedErrorHandler.report(error, ctx);
|
|
66
|
+
return this.#resolvedErrorHandler.handle(error, ctx);
|
|
67
|
+
})
|
|
64
68
|
.finalHandler(finalHandler(this.#router, resolver, ctx))
|
|
65
69
|
.run(middlewareHandler(resolver, ctx))
|
|
66
70
|
.catch((error) => {
|
|
@@ -3,11 +3,25 @@ import type { QSParserConfig } from './qs.js';
|
|
|
3
3
|
import type { RequestConfig } from './request.js';
|
|
4
4
|
import type { ResponseConfig } from './response.js';
|
|
5
5
|
import type { HttpContext } from '../http_context/main.js';
|
|
6
|
+
export type HttpError = {
|
|
7
|
+
message: string;
|
|
8
|
+
status: number;
|
|
9
|
+
code?: string;
|
|
10
|
+
stack?: string;
|
|
11
|
+
cause?: any;
|
|
12
|
+
messages?: any;
|
|
13
|
+
errors?: any;
|
|
14
|
+
handle?: (...args: any[]) => any;
|
|
15
|
+
report?: (...args: any[]) => any;
|
|
16
|
+
};
|
|
17
|
+
export type StatusPageRange = `${number}..${number}`;
|
|
18
|
+
export type StatusPageRenderer = (error: HttpError, ctx: HttpContext) => any | Promise<any>;
|
|
6
19
|
export type HttpRequestFinishedPayload = {
|
|
7
20
|
ctx: HttpContext;
|
|
8
21
|
duration: [number, number];
|
|
9
22
|
};
|
|
10
23
|
export type ServerErrorHandler = {
|
|
24
|
+
report: (error: any, ctx: HttpContext) => any;
|
|
11
25
|
handle: (error: any, ctx: HttpContext) => any;
|
|
12
26
|
};
|
|
13
27
|
export type ErrorHandlerAsAClass = Constructor<ServerErrorHandler>;
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/http-server",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.6.0-0",
|
|
4
4
|
"description": "AdonisJS HTTP server with support packed with Routing and Cookies",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
|
8
8
|
"build/src",
|
|
9
|
-
"build/
|
|
9
|
+
"build/factories",
|
|
10
10
|
"build/index.d.ts",
|
|
11
11
|
"build/index.js"
|
|
12
12
|
],
|
|
13
13
|
"exports": {
|
|
14
14
|
".": "./build/index.js",
|
|
15
15
|
"./types": "./build/src/types/main.js",
|
|
16
|
-
"./
|
|
16
|
+
"./factories": "./build/factories/main.js"
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
19
|
"pretest": "npm run lint",
|
|
@@ -39,12 +39,12 @@
|
|
|
39
39
|
"author": "virk,adonisjs",
|
|
40
40
|
"license": "MIT",
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@adonisjs/application": "^6.8.
|
|
43
|
-
"@adonisjs/config": "^4.1.
|
|
44
|
-
"@adonisjs/encryption": "^5.1.
|
|
45
|
-
"@adonisjs/events": "^8.4.
|
|
46
|
-
"@adonisjs/fold": "^9.9.
|
|
47
|
-
"@adonisjs/logger": "^5.
|
|
42
|
+
"@adonisjs/application": "^6.8.1-0",
|
|
43
|
+
"@adonisjs/config": "^4.1.4-0",
|
|
44
|
+
"@adonisjs/encryption": "^5.1.1-0",
|
|
45
|
+
"@adonisjs/events": "^8.4.4-0",
|
|
46
|
+
"@adonisjs/fold": "^9.9.1-0",
|
|
47
|
+
"@adonisjs/logger": "^5.4.0-0",
|
|
48
48
|
"@commitlint/cli": "^17.4.2",
|
|
49
49
|
"@commitlint/config-conventional": "^17.4.2",
|
|
50
50
|
"@fastify/middie": "^8.1.0",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"eslint-config-prettier": "^8.6.0",
|
|
81
81
|
"eslint-plugin-adonis": "^3.0.3",
|
|
82
82
|
"eslint-plugin-prettier": "^4.2.1",
|
|
83
|
-
"fastify": "^4.
|
|
83
|
+
"fastify": "^4.12.0",
|
|
84
84
|
"fs-extra": "^11.1.0",
|
|
85
85
|
"github-label-sync": "^2.2.0",
|
|
86
86
|
"http-status-codes": "^2.2.0",
|
|
@@ -113,14 +113,15 @@
|
|
|
113
113
|
"qs": "^6.11.0",
|
|
114
114
|
"tmp-cache": "^1.1.0",
|
|
115
115
|
"type-is": "^1.6.18",
|
|
116
|
-
"vary": "^1.1.2"
|
|
116
|
+
"vary": "^1.1.2",
|
|
117
|
+
"youch": "^3.2.2"
|
|
117
118
|
},
|
|
118
119
|
"peerDependencies": {
|
|
119
|
-
"@adonisjs/application": "^6.8.
|
|
120
|
-
"@adonisjs/encryption": "^5.1.
|
|
121
|
-
"@adonisjs/events": "^8.4.
|
|
122
|
-
"@adonisjs/fold": "^9.9.
|
|
123
|
-
"@adonisjs/logger": "^5.
|
|
120
|
+
"@adonisjs/application": "^6.8.1-0",
|
|
121
|
+
"@adonisjs/encryption": "^5.1.1-0",
|
|
122
|
+
"@adonisjs/events": "^8.4.4-0",
|
|
123
|
+
"@adonisjs/fold": "^9.9.1-0",
|
|
124
|
+
"@adonisjs/logger": "^5.4.0-0"
|
|
124
125
|
},
|
|
125
126
|
"repository": {
|
|
126
127
|
"type": "git",
|
|
@@ -183,7 +184,7 @@
|
|
|
183
184
|
],
|
|
184
185
|
"exclude": [
|
|
185
186
|
"tests/**",
|
|
186
|
-
"
|
|
187
|
+
"factories/**",
|
|
187
188
|
".yalc/**"
|
|
188
189
|
]
|
|
189
190
|
}
|