@adonisjs/http-server 6.8.2-8 → 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.
- package/build/chunk-XX72ATFY.js +4388 -0
- package/build/factories/main.d.ts +149 -6
- package/build/factories/main.js +331 -14
- package/build/index.d.ts +272 -14
- package/build/index.js +308 -22
- package/build/{src/server/main.d.ts → main-29eaaee4.d.ts} +12 -17
- package/build/main-e5b46c83.d.ts +2210 -0
- package/build/src/types/main.d.ts +14 -7
- package/build/src/types/main.js +0 -15
- package/package.json +65 -55
- package/build/factories/http_context.d.ts +0 -25
- package/build/factories/http_context.js +0 -51
- package/build/factories/http_server.d.ts +0 -8
- package/build/factories/http_server.js +0 -26
- package/build/factories/qs_parser_factory.d.ts +0 -20
- package/build/factories/qs_parser_factory.js +0 -44
- package/build/factories/request.d.ts +0 -29
- package/build/factories/request.js +0 -73
- package/build/factories/response.d.ts +0 -29
- package/build/factories/response.js +0 -77
- package/build/factories/router.d.ts +0 -23
- package/build/factories/router.js +0 -45
- package/build/factories/server_factory.d.ts +0 -29
- package/build/factories/server_factory.js +0 -65
- package/build/src/cookies/client.d.ts +0 -37
- package/build/src/cookies/client.js +0 -84
- package/build/src/cookies/drivers/encrypted.d.ts +0 -16
- package/build/src/cookies/drivers/encrypted.js +0 -36
- package/build/src/cookies/drivers/plain.d.ts +0 -15
- package/build/src/cookies/drivers/plain.js +0 -33
- package/build/src/cookies/drivers/signed.d.ts +0 -16
- package/build/src/cookies/drivers/signed.js +0 -36
- package/build/src/cookies/parser.d.ts +0 -37
- package/build/src/cookies/parser.js +0 -167
- package/build/src/cookies/serializer.d.ts +0 -33
- package/build/src/cookies/serializer.js +0 -79
- package/build/src/debug.d.ts +0 -3
- package/build/src/debug.js +0 -10
- package/build/src/define_config.d.ts +0 -5
- package/build/src/define_config.js +0 -51
- package/build/src/define_middleware.d.ts +0 -11
- package/build/src/define_middleware.js +0 -35
- package/build/src/exception_handler.d.ts +0 -90
- package/build/src/exception_handler.js +0 -239
- package/build/src/exceptions.d.ts +0 -84
- package/build/src/exceptions.js +0 -38
- package/build/src/helpers.d.ts +0 -23
- package/build/src/helpers.js +0 -84
- package/build/src/http_context/local_storage.d.ts +0 -12
- package/build/src/http_context/local_storage.js +0 -39
- package/build/src/http_context/main.d.ts +0 -58
- package/build/src/http_context/main.js +0 -105
- package/build/src/qs.d.ts +0 -11
- package/build/src/qs.js +0 -25
- package/build/src/redirect.d.ts +0 -42
- package/build/src/redirect.js +0 -140
- package/build/src/request.d.ts +0 -565
- package/build/src/request.js +0 -865
- package/build/src/response.d.ts +0 -540
- package/build/src/response.js +0 -1208
- package/build/src/router/brisk.d.ts +0 -42
- package/build/src/router/brisk.js +0 -85
- package/build/src/router/executor.d.ts +0 -8
- package/build/src/router/executor.js +0 -29
- package/build/src/router/factories/use_return_value.d.ts +0 -6
- package/build/src/router/factories/use_return_value.js +0 -22
- package/build/src/router/group.d.ts +0 -65
- package/build/src/router/group.js +0 -207
- package/build/src/router/lookup_store/main.d.ts +0 -49
- package/build/src/router/lookup_store/main.js +0 -86
- package/build/src/router/lookup_store/route_finder.d.ts +0 -21
- package/build/src/router/lookup_store/route_finder.js +0 -49
- package/build/src/router/lookup_store/url_builder.d.ts +0 -52
- package/build/src/router/lookup_store/url_builder.js +0 -209
- package/build/src/router/main.d.ts +0 -128
- package/build/src/router/main.js +0 -316
- package/build/src/router/matchers.d.ts +0 -27
- package/build/src/router/matchers.js +0 -36
- package/build/src/router/parser.d.ts +0 -5
- package/build/src/router/parser.js +0 -17
- package/build/src/router/resource.d.ts +0 -54
- package/build/src/router/resource.js +0 -216
- package/build/src/router/route.d.ts +0 -92
- package/build/src/router/route.js +0 -293
- package/build/src/router/store.d.ts +0 -66
- package/build/src/router/store.js +0 -195
- package/build/src/server/factories/final_handler.d.ts +0 -9
- package/build/src/server/factories/final_handler.js +0 -30
- package/build/src/server/factories/middleware_handler.d.ts +0 -8
- package/build/src/server/factories/middleware_handler.js +0 -16
- package/build/src/server/factories/write_response.d.ts +0 -6
- package/build/src/server/factories/write_response.js +0 -24
- package/build/src/server/main.js +0 -283
- package/build/src/types/base.d.ts +0 -19
- package/build/src/types/base.js +0 -9
- package/build/src/types/middleware.d.ts +0 -35
- package/build/src/types/middleware.js +0 -9
- package/build/src/types/qs.d.ts +0 -68
- package/build/src/types/qs.js +0 -9
- package/build/src/types/request.d.ts +0 -39
- package/build/src/types/request.js +0 -9
- package/build/src/types/response.d.ts +0 -45
- package/build/src/types/response.js +0 -9
- package/build/src/types/route.d.ts +0 -165
- package/build/src/types/route.js +0 -9
- package/build/src/types/server.d.ts +0 -72
- package/build/src/types/server.js +0 -9
|
@@ -1,79 +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 cookie from 'cookie';
|
|
10
|
-
import string from '@poppinss/utils/string';
|
|
11
|
-
import { CookieClient } from './client.js';
|
|
12
|
-
/**
|
|
13
|
-
* Cookies serializer is used to serialize a value to be set on the `Set-Cookie`
|
|
14
|
-
* header. You can `encode`, `sign` on `encrypt` cookies using the serializer
|
|
15
|
-
* and then set them individually using the `set-cookie` header.
|
|
16
|
-
*/
|
|
17
|
-
export class CookieSerializer {
|
|
18
|
-
#client;
|
|
19
|
-
constructor(encryption) {
|
|
20
|
-
this.#client = new CookieClient(encryption);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Serializes the key-value pair to a string, that can be set on the
|
|
24
|
-
* `Set-Cookie` header.
|
|
25
|
-
*/
|
|
26
|
-
#serializeAsCookie(key, value, options) {
|
|
27
|
-
/**
|
|
28
|
-
* Invoked expires method to get the date
|
|
29
|
-
*/
|
|
30
|
-
let expires = options?.expires;
|
|
31
|
-
if (typeof expires === 'function') {
|
|
32
|
-
expires = expires();
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Parse string based max age to seconds
|
|
36
|
-
*/
|
|
37
|
-
let maxAge = options?.maxAge ? string.seconds.parse(options?.maxAge) : undefined;
|
|
38
|
-
const parsedOptions = Object.assign({}, options, { maxAge, expires });
|
|
39
|
-
return cookie.serialize(key, value, parsedOptions);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Encodes value as a plain cookie. By default, the plain value will be converted
|
|
43
|
-
* to a string using "JSON.stringify" method and then encoded as a base64 string.
|
|
44
|
-
*
|
|
45
|
-
* You can disable encoding of the cookie by setting `options.encoded = false`.
|
|
46
|
-
*
|
|
47
|
-
* ```ts
|
|
48
|
-
* serializer.encode('name', 'virk')
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
encode(key, value, options) {
|
|
52
|
-
const packedValue = options?.encode === false ? value : this.#client.encode(key, value);
|
|
53
|
-
if (packedValue === null || packedValue === undefined) {
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
return this.#serializeAsCookie(key, packedValue, options);
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Sign a key-value pair to a signed cookie. The signed value has a
|
|
60
|
-
* verification hash attached to it to detect data tampering.
|
|
61
|
-
*/
|
|
62
|
-
sign(key, value, options) {
|
|
63
|
-
const packedValue = this.#client.sign(key, value);
|
|
64
|
-
if (packedValue === null) {
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
return this.#serializeAsCookie(key, packedValue, options);
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Encrypts a key-value pair to an encrypted cookie.
|
|
71
|
-
*/
|
|
72
|
-
encrypt(key, value, options) {
|
|
73
|
-
const packedValue = this.#client.encrypt(key, value);
|
|
74
|
-
if (packedValue === null) {
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
return this.#serializeAsCookie(key, packedValue, options);
|
|
78
|
-
}
|
|
79
|
-
}
|
package/build/src/debug.d.ts
DELETED
package/build/src/debug.js
DELETED
|
@@ -1,10 +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 { debuglog } from 'node:util';
|
|
10
|
-
export default debuglog('adonisjs:http');
|
|
@@ -1,51 +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 proxyAddr from 'proxy-addr';
|
|
10
|
-
import string from '@poppinss/utils/string';
|
|
11
|
-
/**
|
|
12
|
-
* Define configuration for the HTTP server
|
|
13
|
-
*/
|
|
14
|
-
export function defineConfig(config) {
|
|
15
|
-
const normalizedConfig = {
|
|
16
|
-
allowMethodSpoofing: false,
|
|
17
|
-
trustProxy: proxyAddr.compile('loopback'),
|
|
18
|
-
subdomainOffset: 2,
|
|
19
|
-
generateRequestId: false,
|
|
20
|
-
useAsyncLocalStorage: false,
|
|
21
|
-
etag: false,
|
|
22
|
-
jsonpCallbackName: 'callback',
|
|
23
|
-
cookie: {
|
|
24
|
-
maxAge: '2h',
|
|
25
|
-
path: '/',
|
|
26
|
-
httpOnly: true,
|
|
27
|
-
secure: false,
|
|
28
|
-
sameSite: false,
|
|
29
|
-
},
|
|
30
|
-
qs: {
|
|
31
|
-
parse: {
|
|
32
|
-
depth: 5,
|
|
33
|
-
parameterLimit: 1000,
|
|
34
|
-
allowSparse: false,
|
|
35
|
-
arrayLimit: 20,
|
|
36
|
-
comma: true,
|
|
37
|
-
},
|
|
38
|
-
stringify: {
|
|
39
|
-
encode: true,
|
|
40
|
-
encodeValuesOnly: false,
|
|
41
|
-
arrayFormat: 'indices',
|
|
42
|
-
skipNulls: false,
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
...config,
|
|
46
|
-
};
|
|
47
|
-
if (normalizedConfig.cookie.maxAge) {
|
|
48
|
-
normalizedConfig.cookie.maxAge = string.seconds.parse(normalizedConfig.cookie.maxAge);
|
|
49
|
-
}
|
|
50
|
-
return normalizedConfig;
|
|
51
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { LazyImport, UnWrapLazyImport } from './types/base.js';
|
|
2
|
-
import type { GetMiddlewareArgs, MiddlewareAsClass, ParsedGlobalMiddleware } from './types/middleware.js';
|
|
3
|
-
/**
|
|
4
|
-
* Define an collection of named middleware. The collection gets converted
|
|
5
|
-
* into a collection of factory functions. Calling the function returns
|
|
6
|
-
* a reference to the executable middleware.
|
|
7
|
-
*/
|
|
8
|
-
export declare function defineNamedMiddleware<NamedMiddleware extends Record<string | number | symbol, LazyImport<MiddlewareAsClass>>>(collection: NamedMiddleware): { [K in keyof NamedMiddleware]: <Args extends GetMiddlewareArgs<UnWrapLazyImport<NamedMiddleware[K]>>>(...args: Args) => {
|
|
9
|
-
name: K;
|
|
10
|
-
args: Args[0];
|
|
11
|
-
} & ParsedGlobalMiddleware; };
|
|
@@ -1,35 +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 { moduleImporter } from '@adonisjs/fold';
|
|
10
|
-
/**
|
|
11
|
-
* Converts a middleware name and its lazy import to a factory function. The function
|
|
12
|
-
* can than later be used to reference the middleware with different arguments
|
|
13
|
-
* every time.
|
|
14
|
-
*/
|
|
15
|
-
function middlewareReferenceBuilder(name, middleware) {
|
|
16
|
-
const handler = moduleImporter(middleware, 'handle').toHandleMethod();
|
|
17
|
-
return function (...args) {
|
|
18
|
-
return {
|
|
19
|
-
name,
|
|
20
|
-
args: args[0],
|
|
21
|
-
...handler,
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Define an collection of named middleware. The collection gets converted
|
|
27
|
-
* into a collection of factory functions. Calling the function returns
|
|
28
|
-
* a reference to the executable middleware.
|
|
29
|
-
*/
|
|
30
|
-
export function defineNamedMiddleware(collection) {
|
|
31
|
-
return Object.keys(collection).reduce((result, key) => {
|
|
32
|
-
result[key] = middlewareReferenceBuilder(key, collection[key]);
|
|
33
|
-
return result;
|
|
34
|
-
}, {});
|
|
35
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import type { Level } from '@adonisjs/logger/types';
|
|
2
|
-
import type { HttpContext } from './http_context/main.js';
|
|
3
|
-
import type { HttpError, StatusPageRange, StatusPageRenderer } from './types/server.js';
|
|
4
|
-
/**
|
|
5
|
-
* The base HTTP exception handler one can inherit from to handle
|
|
6
|
-
* HTTP exceptions.
|
|
7
|
-
*
|
|
8
|
-
* The HTTP exception handler has support for
|
|
9
|
-
*
|
|
10
|
-
* - Ability to render exceptions by calling the render method on the exception.
|
|
11
|
-
* - Rendering status pages
|
|
12
|
-
* - Pretty printing errors during development
|
|
13
|
-
* - Transforming errors to JSON or HTML using content negotiation
|
|
14
|
-
* - Reporting errors
|
|
15
|
-
*/
|
|
16
|
-
export declare class ExceptionHandler {
|
|
17
|
-
#private;
|
|
18
|
-
/**
|
|
19
|
-
* Whether or not to render debug info. When set to true, the errors
|
|
20
|
-
* will have the complete error stack.
|
|
21
|
-
*/
|
|
22
|
-
protected debug: boolean;
|
|
23
|
-
/**
|
|
24
|
-
* Whether or not to render status pages. When set to true, the unhandled
|
|
25
|
-
* errors with matching status codes will be rendered using a status
|
|
26
|
-
* page.
|
|
27
|
-
*/
|
|
28
|
-
protected renderStatusPages: boolean;
|
|
29
|
-
/**
|
|
30
|
-
* A collection of error status code range and the view to render.
|
|
31
|
-
*/
|
|
32
|
-
protected statusPages: Record<StatusPageRange, StatusPageRenderer>;
|
|
33
|
-
/**
|
|
34
|
-
* Renderers for rendering an error.
|
|
35
|
-
*/
|
|
36
|
-
protected renderers: {
|
|
37
|
-
html: (error: HttpError, ctx: HttpContext) => Promise<void>;
|
|
38
|
-
json: (error: HttpError, ctx: HttpContext) => Promise<void>;
|
|
39
|
-
json_api: (error: HttpError, ctx: HttpContext) => Promise<void>;
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Enable/disable errors reporting
|
|
43
|
-
*/
|
|
44
|
-
protected reportErrors: boolean;
|
|
45
|
-
/**
|
|
46
|
-
* An array of exception classes to ignore when
|
|
47
|
-
* reporting an error
|
|
48
|
-
*/
|
|
49
|
-
protected ignoreExceptions: any[];
|
|
50
|
-
/**
|
|
51
|
-
* An array of HTTP status codes to ignore when reporting
|
|
52
|
-
* an error
|
|
53
|
-
*/
|
|
54
|
-
protected ignoreStatuses: number[];
|
|
55
|
-
/**
|
|
56
|
-
* An array of error codes to ignore when reporting
|
|
57
|
-
* an error
|
|
58
|
-
*/
|
|
59
|
-
protected ignoreCodes: string[];
|
|
60
|
-
/**
|
|
61
|
-
* Error reporting context
|
|
62
|
-
*/
|
|
63
|
-
protected context(ctx: HttpContext): any;
|
|
64
|
-
/**
|
|
65
|
-
* The format in which the error should be rendered.
|
|
66
|
-
*/
|
|
67
|
-
protected getResponseFormat(ctx: HttpContext): 'html' | 'json' | 'json_api';
|
|
68
|
-
/**
|
|
69
|
-
* Returns the log level for an error based upon the error
|
|
70
|
-
* status code.
|
|
71
|
-
*/
|
|
72
|
-
protected getErrorLogLevel(error: HttpError): Level;
|
|
73
|
-
/**
|
|
74
|
-
* A boolean to control if errors should be rendered with
|
|
75
|
-
* all the available debugging info.
|
|
76
|
-
*/
|
|
77
|
-
protected isDebuggingEnabled(_: HttpContext): boolean;
|
|
78
|
-
/**
|
|
79
|
-
* Returns a boolean by checking if an error should be reported.
|
|
80
|
-
*/
|
|
81
|
-
protected shouldReport(error: HttpError): boolean;
|
|
82
|
-
/**
|
|
83
|
-
* Reports an error during an HTTP request
|
|
84
|
-
*/
|
|
85
|
-
report(error: unknown, ctx: HttpContext): Promise<void>;
|
|
86
|
-
/**
|
|
87
|
-
* Handles the error during the HTTP request.
|
|
88
|
-
*/
|
|
89
|
-
handle(error: unknown, ctx: HttpContext): Promise<any>;
|
|
90
|
-
}
|
|
@@ -1,239 +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 is from '@sindresorhus/is';
|
|
10
|
-
import { parseRange } from './helpers.js';
|
|
11
|
-
import * as errors from './exceptions.js';
|
|
12
|
-
/**
|
|
13
|
-
* The base HTTP exception handler one can inherit from to handle
|
|
14
|
-
* HTTP exceptions.
|
|
15
|
-
*
|
|
16
|
-
* The HTTP exception handler has support for
|
|
17
|
-
*
|
|
18
|
-
* - Ability to render exceptions by calling the render method on the exception.
|
|
19
|
-
* - Rendering status pages
|
|
20
|
-
* - Pretty printing errors during development
|
|
21
|
-
* - Transforming errors to JSON or HTML using content negotiation
|
|
22
|
-
* - Reporting errors
|
|
23
|
-
*/
|
|
24
|
-
export class ExceptionHandler {
|
|
25
|
-
/**
|
|
26
|
-
* Whether or not to render debug info. When set to true, the errors
|
|
27
|
-
* will have the complete error stack.
|
|
28
|
-
*/
|
|
29
|
-
debug = process.env.NODE_ENV !== 'production';
|
|
30
|
-
/**
|
|
31
|
-
* Whether or not to render status pages. When set to true, the unhandled
|
|
32
|
-
* errors with matching status codes will be rendered using a status
|
|
33
|
-
* page.
|
|
34
|
-
*/
|
|
35
|
-
renderStatusPages = process.env.NODE_ENV === 'production';
|
|
36
|
-
/**
|
|
37
|
-
* A collection of error status code range and the view to render.
|
|
38
|
-
*/
|
|
39
|
-
statusPages = {};
|
|
40
|
-
/**
|
|
41
|
-
* Computed from the status pages property
|
|
42
|
-
*/
|
|
43
|
-
#expandedStatusPages;
|
|
44
|
-
/**
|
|
45
|
-
* Renderers for rendering an error.
|
|
46
|
-
*/
|
|
47
|
-
renderers = {
|
|
48
|
-
html: async (error, ctx) => {
|
|
49
|
-
if (this.isDebuggingEnabled(ctx)) {
|
|
50
|
-
const { default: Youch } = await import('youch');
|
|
51
|
-
const html = await new Youch(error, ctx.request.request).toHTML();
|
|
52
|
-
ctx.response.status(error.status).send(html);
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
ctx.response.status(error.status).send(`<p> ${error.message} </p>`);
|
|
56
|
-
},
|
|
57
|
-
json: async (error, ctx) => {
|
|
58
|
-
if (this.isDebuggingEnabled(ctx)) {
|
|
59
|
-
const { default: Youch } = await import('youch');
|
|
60
|
-
const json = await new Youch(error, ctx.request.request).toJSON();
|
|
61
|
-
ctx.response.status(error.status).send(json.error);
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
ctx.response.status(error.status).send({ message: error.message });
|
|
65
|
-
},
|
|
66
|
-
json_api: async (error, ctx) => {
|
|
67
|
-
if (this.isDebuggingEnabled(ctx)) {
|
|
68
|
-
const { default: Youch } = await import('youch');
|
|
69
|
-
const json = await new Youch(error, ctx.request.request).toJSON();
|
|
70
|
-
ctx.response.status(error.status).send(json.error);
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
ctx.response.status(error.status).send({
|
|
74
|
-
errors: [
|
|
75
|
-
{
|
|
76
|
-
title: error.message,
|
|
77
|
-
code: error.code,
|
|
78
|
-
status: error.status,
|
|
79
|
-
},
|
|
80
|
-
],
|
|
81
|
-
});
|
|
82
|
-
},
|
|
83
|
-
};
|
|
84
|
-
/**
|
|
85
|
-
* Enable/disable errors reporting
|
|
86
|
-
*/
|
|
87
|
-
reportErrors = true;
|
|
88
|
-
/**
|
|
89
|
-
* An array of exception classes to ignore when
|
|
90
|
-
* reporting an error
|
|
91
|
-
*/
|
|
92
|
-
ignoreExceptions = [
|
|
93
|
-
errors.E_HTTP_EXCEPTION,
|
|
94
|
-
errors.E_ROUTE_NOT_FOUND,
|
|
95
|
-
errors.E_CANNOT_LOOKUP_ROUTE,
|
|
96
|
-
errors.E_HTTP_REQUEST_ABORTED,
|
|
97
|
-
];
|
|
98
|
-
/**
|
|
99
|
-
* An array of HTTP status codes to ignore when reporting
|
|
100
|
-
* an error
|
|
101
|
-
*/
|
|
102
|
-
ignoreStatuses = [400, 422, 401];
|
|
103
|
-
/**
|
|
104
|
-
* An array of error codes to ignore when reporting
|
|
105
|
-
* an error
|
|
106
|
-
*/
|
|
107
|
-
ignoreCodes = [];
|
|
108
|
-
/**
|
|
109
|
-
* Expands status pages
|
|
110
|
-
*/
|
|
111
|
-
#expandStatusPages() {
|
|
112
|
-
if (!this.#expandedStatusPages) {
|
|
113
|
-
this.#expandedStatusPages = Object.keys(this.statusPages).reduce((result, range) => {
|
|
114
|
-
const renderer = this.statusPages[range];
|
|
115
|
-
result = Object.assign(result, parseRange(range, renderer));
|
|
116
|
-
return result;
|
|
117
|
-
}, {});
|
|
118
|
-
}
|
|
119
|
-
return this.#expandedStatusPages;
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Forcefully tweaking the type of the error object to
|
|
123
|
-
* have known properties.
|
|
124
|
-
*/
|
|
125
|
-
#toHttpError(error) {
|
|
126
|
-
const httpError = is.object(error) ? error : new Error(String(error));
|
|
127
|
-
httpError.message = httpError.message || 'Internal server error';
|
|
128
|
-
httpError.status = httpError.status || 500;
|
|
129
|
-
return httpError;
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Error reporting context
|
|
133
|
-
*/
|
|
134
|
-
context(ctx) {
|
|
135
|
-
const requestId = ctx.request.id();
|
|
136
|
-
return requestId
|
|
137
|
-
? {
|
|
138
|
-
'x-request-id': requestId,
|
|
139
|
-
}
|
|
140
|
-
: {};
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* The format in which the error should be rendered.
|
|
144
|
-
*/
|
|
145
|
-
getResponseFormat(ctx) {
|
|
146
|
-
switch (ctx.request.accepts(['html', 'application/vnd.api+json', 'json'])) {
|
|
147
|
-
case 'application/vnd.api+json':
|
|
148
|
-
return 'json_api';
|
|
149
|
-
case 'json':
|
|
150
|
-
return 'json';
|
|
151
|
-
case 'html':
|
|
152
|
-
default:
|
|
153
|
-
return 'html';
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Returns the log level for an error based upon the error
|
|
158
|
-
* status code.
|
|
159
|
-
*/
|
|
160
|
-
getErrorLogLevel(error) {
|
|
161
|
-
if (error.status >= 500) {
|
|
162
|
-
return 'error';
|
|
163
|
-
}
|
|
164
|
-
if (error.status >= 400) {
|
|
165
|
-
return 'warn';
|
|
166
|
-
}
|
|
167
|
-
return 'info';
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* A boolean to control if errors should be rendered with
|
|
171
|
-
* all the available debugging info.
|
|
172
|
-
*/
|
|
173
|
-
isDebuggingEnabled(_) {
|
|
174
|
-
return this.debug;
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Returns a boolean by checking if an error should be reported.
|
|
178
|
-
*/
|
|
179
|
-
shouldReport(error) {
|
|
180
|
-
if (this.reportErrors === false) {
|
|
181
|
-
return false;
|
|
182
|
-
}
|
|
183
|
-
if (this.ignoreStatuses.includes(error.status)) {
|
|
184
|
-
return false;
|
|
185
|
-
}
|
|
186
|
-
if (error.code && this.ignoreCodes.includes(error.code)) {
|
|
187
|
-
return false;
|
|
188
|
-
}
|
|
189
|
-
if (this.ignoreExceptions.find((exception) => error instanceof exception)) {
|
|
190
|
-
return false;
|
|
191
|
-
}
|
|
192
|
-
return true;
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Reports an error during an HTTP request
|
|
196
|
-
*/
|
|
197
|
-
async report(error, ctx) {
|
|
198
|
-
const httpError = this.#toHttpError(error);
|
|
199
|
-
if (!this.shouldReport(httpError)) {
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
if (typeof httpError.report === 'function') {
|
|
203
|
-
httpError.report(httpError, ctx);
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Log the error using the logger
|
|
208
|
-
*/
|
|
209
|
-
const level = this.getErrorLogLevel(httpError);
|
|
210
|
-
ctx.logger.log(level, {
|
|
211
|
-
...(level === 'error' || level === 'fatal' ? { err: httpError } : {}),
|
|
212
|
-
...this.context(ctx),
|
|
213
|
-
}, httpError.message);
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Handles the error during the HTTP request.
|
|
217
|
-
*/
|
|
218
|
-
async handle(error, ctx) {
|
|
219
|
-
const httpError = this.#toHttpError(error);
|
|
220
|
-
/**
|
|
221
|
-
* Self handle exception
|
|
222
|
-
*/
|
|
223
|
-
if (typeof httpError.handle === 'function') {
|
|
224
|
-
return httpError.handle(httpError, ctx);
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Render status page
|
|
228
|
-
*/
|
|
229
|
-
const statusPages = this.#expandStatusPages();
|
|
230
|
-
if (this.renderStatusPages && statusPages[httpError.status]) {
|
|
231
|
-
return statusPages[httpError.status](httpError, ctx);
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* Use the format renderers.
|
|
235
|
-
*/
|
|
236
|
-
const responseFormat = this.getResponseFormat(ctx);
|
|
237
|
-
return this.renderers[responseFormat](httpError, ctx);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import { Exception } from '@poppinss/utils';
|
|
3
|
-
import type { HttpContext } from './http_context/main.js';
|
|
4
|
-
export declare const E_ROUTE_NOT_FOUND: new (args: [method: string, url: string], options?: ErrorOptions | undefined) => Exception;
|
|
5
|
-
export declare const E_CANNOT_LOOKUP_ROUTE: new (args: [routeIdentifier: string], options?: ErrorOptions | undefined) => Exception;
|
|
6
|
-
export declare const E_HTTP_EXCEPTION: {
|
|
7
|
-
new (message?: string | undefined, options?: (ErrorOptions & {
|
|
8
|
-
code?: string | undefined;
|
|
9
|
-
status?: number | undefined;
|
|
10
|
-
}) | undefined): {
|
|
11
|
-
body: any;
|
|
12
|
-
name: string;
|
|
13
|
-
help?: string | undefined;
|
|
14
|
-
code?: string | undefined;
|
|
15
|
-
status: number;
|
|
16
|
-
toString(): string;
|
|
17
|
-
readonly [Symbol.toStringTag]: string;
|
|
18
|
-
message: string;
|
|
19
|
-
stack?: string | undefined;
|
|
20
|
-
cause?: unknown;
|
|
21
|
-
};
|
|
22
|
-
code: string;
|
|
23
|
-
/**
|
|
24
|
-
* This method returns an instance of the exception class
|
|
25
|
-
*/
|
|
26
|
-
invoke(body: any, status: number, code?: string): {
|
|
27
|
-
body: any;
|
|
28
|
-
name: string;
|
|
29
|
-
help?: string | undefined;
|
|
30
|
-
code?: string | undefined;
|
|
31
|
-
status: number;
|
|
32
|
-
toString(): string;
|
|
33
|
-
readonly [Symbol.toStringTag]: string;
|
|
34
|
-
message: string;
|
|
35
|
-
stack?: string | undefined;
|
|
36
|
-
cause?: unknown;
|
|
37
|
-
};
|
|
38
|
-
help?: string | undefined;
|
|
39
|
-
status?: number | undefined;
|
|
40
|
-
message?: string | undefined;
|
|
41
|
-
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
|
|
42
|
-
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
43
|
-
stackTraceLimit: number;
|
|
44
|
-
};
|
|
45
|
-
export declare const E_HTTP_REQUEST_ABORTED: {
|
|
46
|
-
new (message?: string | undefined, options?: (ErrorOptions & {
|
|
47
|
-
code?: string | undefined;
|
|
48
|
-
status?: number | undefined;
|
|
49
|
-
}) | undefined): {
|
|
50
|
-
handle(error: any, ctx: HttpContext): void;
|
|
51
|
-
body: any;
|
|
52
|
-
name: string;
|
|
53
|
-
help?: string | undefined;
|
|
54
|
-
code?: string | undefined;
|
|
55
|
-
status: number;
|
|
56
|
-
toString(): string;
|
|
57
|
-
readonly [Symbol.toStringTag]: string;
|
|
58
|
-
message: string;
|
|
59
|
-
stack?: string | undefined;
|
|
60
|
-
cause?: unknown;
|
|
61
|
-
};
|
|
62
|
-
code: string;
|
|
63
|
-
/**
|
|
64
|
-
* This method returns an instance of the exception class
|
|
65
|
-
*/
|
|
66
|
-
invoke(body: any, status: number, code?: string): {
|
|
67
|
-
body: any;
|
|
68
|
-
name: string;
|
|
69
|
-
help?: string | undefined;
|
|
70
|
-
code?: string | undefined;
|
|
71
|
-
status: number;
|
|
72
|
-
toString(): string;
|
|
73
|
-
readonly [Symbol.toStringTag]: string;
|
|
74
|
-
message: string;
|
|
75
|
-
stack?: string | undefined;
|
|
76
|
-
cause?: unknown;
|
|
77
|
-
};
|
|
78
|
-
help?: string | undefined;
|
|
79
|
-
status?: number | undefined;
|
|
80
|
-
message?: string | undefined;
|
|
81
|
-
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
|
|
82
|
-
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
83
|
-
stackTraceLimit: number;
|
|
84
|
-
};
|
package/build/src/exceptions.js
DELETED
|
@@ -1,38 +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 { createError, Exception } from '@poppinss/utils';
|
|
10
|
-
export const E_ROUTE_NOT_FOUND = createError('Cannot %s:%s', 'E_ROUTE_NOT_FOUND', 404);
|
|
11
|
-
export const E_CANNOT_LOOKUP_ROUTE = createError('Cannot lookup route "%s"', 'E_CANNOT_LOOKUP_ROUTE', 500);
|
|
12
|
-
export const E_HTTP_EXCEPTION = class HttpException extends Exception {
|
|
13
|
-
body;
|
|
14
|
-
static code = 'E_HTTP_EXCEPTION';
|
|
15
|
-
/**
|
|
16
|
-
* This method returns an instance of the exception class
|
|
17
|
-
*/
|
|
18
|
-
static invoke(body, status, code = 'E_HTTP_EXCEPTION') {
|
|
19
|
-
if (body === null || body === undefined) {
|
|
20
|
-
const error = new this('HTTP Exception', { status, code });
|
|
21
|
-
error.body = 'Internal server error';
|
|
22
|
-
return error;
|
|
23
|
-
}
|
|
24
|
-
if (typeof body === 'object') {
|
|
25
|
-
const error = new this(body.message || 'HTTP Exception', { status, code });
|
|
26
|
-
error.body = body;
|
|
27
|
-
return error;
|
|
28
|
-
}
|
|
29
|
-
const error = new this(body, { status, code });
|
|
30
|
-
error.body = body;
|
|
31
|
-
return error;
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
export const E_HTTP_REQUEST_ABORTED = class AbortException extends E_HTTP_EXCEPTION {
|
|
35
|
-
handle(error, ctx) {
|
|
36
|
-
ctx.response.status(error.status).send(error.body);
|
|
37
|
-
}
|
|
38
|
-
};
|
package/build/src/helpers.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Route } from './router/route.js';
|
|
2
|
-
import { BriskRoute } from './router/brisk.js';
|
|
3
|
-
import { RouteGroup } from './router/group.js';
|
|
4
|
-
import type { RouteJSON } from './types/route.js';
|
|
5
|
-
import { RouteResource } from './router/resource.js';
|
|
6
|
-
/**
|
|
7
|
-
* Makes input string consistent by having only the starting
|
|
8
|
-
* slash
|
|
9
|
-
*/
|
|
10
|
-
export declare function dropSlash(input: string): string;
|
|
11
|
-
/**
|
|
12
|
-
* Returns a flat list of routes from the route groups and resources
|
|
13
|
-
*/
|
|
14
|
-
export declare function toRoutesJSON(routes: (RouteGroup | Route | RouteResource | BriskRoute)[]): RouteJSON[];
|
|
15
|
-
/**
|
|
16
|
-
* Helper to know if the remote address should
|
|
17
|
-
* be trusted.
|
|
18
|
-
*/
|
|
19
|
-
export declare function trustProxy(remoteAddress: string, proxyFn: (addr: string, distance: number) => boolean): boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Parses a range expression to an object filled with the range
|
|
22
|
-
*/
|
|
23
|
-
export declare function parseRange<T>(range: string, value: T): Record<number, T>;
|