@adonisjs/http-server 6.8.2-0 → 6.8.2-10
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/README.md +3 -6
- package/build/factories/http_context.d.ts +10 -0
- package/build/factories/http_context.js +27 -0
- package/build/factories/http_server.d.ts +8 -0
- package/build/factories/http_server.js +26 -0
- package/build/factories/main.js +8 -0
- package/build/factories/qs_parser_factory.d.ts +10 -0
- package/build/factories/qs_parser_factory.js +18 -0
- package/build/factories/request.d.ts +10 -0
- package/build/factories/request.js +31 -0
- package/build/factories/response.d.ts +10 -0
- package/build/factories/response.js +34 -0
- package/build/factories/router.d.ts +10 -0
- package/build/factories/router.js +25 -0
- package/build/factories/server_factory.d.ts +10 -0
- package/build/factories/server_factory.js +34 -0
- package/build/index.js +8 -0
- package/build/src/cookies/client.d.ts +25 -0
- package/build/src/cookies/client.js +42 -0
- package/build/src/cookies/drivers/encrypted.d.ts +12 -0
- package/build/src/cookies/drivers/encrypted.js +20 -0
- package/build/src/cookies/drivers/plain.d.ts +12 -0
- package/build/src/cookies/drivers/plain.js +20 -0
- package/build/src/cookies/drivers/signed.d.ts +12 -0
- package/build/src/cookies/drivers/signed.js +20 -0
- package/build/src/cookies/parser.d.ts +28 -0
- package/build/src/cookies/parser.js +98 -0
- package/build/src/cookies/serializer.d.ts +22 -0
- package/build/src/cookies/serializer.js +40 -0
- package/build/src/debug.js +8 -0
- package/build/src/define_config.d.ts +3 -0
- package/build/src/define_config.js +11 -0
- package/build/src/define_middleware.d.ts +5 -0
- package/build/src/define_middleware.js +18 -0
- package/build/src/exception_handler.d.ts +93 -6
- package/build/src/exception_handler.js +203 -44
- package/build/src/exceptions.d.ts +6 -0
- package/build/src/exceptions.js +11 -0
- package/build/src/helpers.d.ts +14 -0
- package/build/src/helpers.js +43 -0
- package/build/src/http_context/local_storage.d.ts +3 -0
- package/build/src/http_context/local_storage.js +25 -0
- package/build/src/http_context/main.d.ts +36 -0
- package/build/src/http_context/main.js +54 -0
- package/build/src/qs.d.ts +4 -0
- package/build/src/qs.js +12 -0
- package/build/src/redirect.d.ts +24 -0
- package/build/src/redirect.js +60 -0
- package/build/src/request.d.ts +466 -0
- package/build/src/request.js +544 -2
- package/build/src/response.d.ts +425 -1
- package/build/src/response.js +611 -11
- package/build/src/router/brisk.d.ts +22 -0
- package/build/src/router/brisk.js +44 -2
- package/build/src/router/executor.d.ts +6 -1
- package/build/src/router/executor.js +14 -1
- package/build/src/router/factories/use_return_value.d.ts +4 -0
- package/build/src/router/factories/use_return_value.js +16 -3
- package/build/src/router/group.d.ts +47 -0
- package/build/src/router/group.js +88 -0
- package/build/src/router/lookup_store/main.d.ts +32 -0
- package/build/src/router/lookup_store/main.js +49 -0
- package/build/src/router/lookup_store/route_finder.d.ts +13 -0
- package/build/src/router/lookup_store/route_finder.js +21 -0
- package/build/src/router/lookup_store/url_builder.d.ts +36 -0
- package/build/src/router/lookup_store/url_builder.js +99 -2
- package/build/src/router/main.d.ts +92 -4
- package/build/src/router/main.js +146 -0
- package/build/src/router/matchers.d.ts +13 -0
- package/build/src/router/matchers.js +21 -0
- package/build/src/router/parser.d.ts +5 -0
- package/build/src/router/parser.js +17 -0
- package/build/src/router/resource.d.ts +30 -1
- package/build/src/router/resource.js +93 -1
- package/build/src/router/route.d.ts +65 -0
- package/build/src/router/route.js +151 -2
- package/build/src/router/store.d.ts +54 -0
- package/build/src/router/store.js +110 -2
- package/build/src/server/factories/final_handler.d.ts +7 -1
- package/build/src/server/factories/final_handler.js +15 -2
- package/build/src/server/factories/middleware_handler.d.ts +3 -0
- package/build/src/server/factories/middleware_handler.js +11 -0
- package/build/src/server/factories/write_response.d.ts +4 -0
- package/build/src/server/factories/write_response.js +12 -0
- package/build/src/server/main.d.ts +48 -0
- package/build/src/server/main.js +142 -5
- package/build/src/types/base.d.ts +12 -0
- package/build/src/types/base.js +8 -0
- package/build/src/types/main.js +8 -0
- package/build/src/types/middleware.d.ts +18 -0
- package/build/src/types/middleware.js +8 -0
- package/build/src/types/qs.d.ts +53 -0
- package/build/src/types/qs.js +8 -0
- package/build/src/types/request.d.ts +32 -0
- package/build/src/types/request.js +8 -0
- package/build/src/types/response.d.ts +27 -0
- package/build/src/types/response.js +8 -0
- package/build/src/types/route.d.ts +89 -1
- package/build/src/types/route.js +8 -0
- package/build/src/types/server.d.ts +36 -1
- package/build/src/types/server.js +8 -0
- package/package.json +53 -76
package/build/src/qs.js
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
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
|
+
*/
|
|
1
9
|
import { parse, stringify } from 'qs';
|
|
10
|
+
/**
|
|
11
|
+
* Query string parser used to parse and stringify query
|
|
12
|
+
* strings.
|
|
13
|
+
*/
|
|
2
14
|
export class Qs {
|
|
3
15
|
#config;
|
|
4
16
|
constructor(config) {
|
package/build/src/redirect.d.ts
CHANGED
|
@@ -4,15 +4,39 @@ import type { Qs } from './qs.js';
|
|
|
4
4
|
import type { Response } from './response.js';
|
|
5
5
|
import type { Router } from './router/main.js';
|
|
6
6
|
import type { MakeUrlOptions } from './types/route.js';
|
|
7
|
+
/**
|
|
8
|
+
* Exposes the API to construct redirect routes
|
|
9
|
+
*/
|
|
7
10
|
export declare class Redirect {
|
|
8
11
|
#private;
|
|
9
12
|
constructor(request: IncomingMessage, response: Response, router: Router, qs: Qs);
|
|
13
|
+
/**
|
|
14
|
+
* Set a custom status code.
|
|
15
|
+
*/
|
|
10
16
|
status(statusCode: number): this;
|
|
17
|
+
/**
|
|
18
|
+
* Clearing query string values added using the
|
|
19
|
+
* "withQs" method
|
|
20
|
+
*/
|
|
11
21
|
clearQs(): this;
|
|
22
|
+
/**
|
|
23
|
+
* Define query string for the redirect. Not passing
|
|
24
|
+
* any value will forward the current request query
|
|
25
|
+
* string.
|
|
26
|
+
*/
|
|
12
27
|
withQs(): this;
|
|
13
28
|
withQs(values: Record<string, any>): this;
|
|
14
29
|
withQs(name: string, value: any): this;
|
|
30
|
+
/**
|
|
31
|
+
* Redirect to the previous path.
|
|
32
|
+
*/
|
|
15
33
|
back(): void;
|
|
34
|
+
/**
|
|
35
|
+
* Redirect the request using a route identifier.
|
|
36
|
+
*/
|
|
16
37
|
toRoute(routeIdentifier: string, params?: any[] | Record<string, any>, options?: MakeUrlOptions): void;
|
|
38
|
+
/**
|
|
39
|
+
* Redirect the request using a path.
|
|
40
|
+
*/
|
|
17
41
|
toPath(url: string): void;
|
|
18
42
|
}
|
package/build/src/redirect.js
CHANGED
|
@@ -1,9 +1,29 @@
|
|
|
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
|
+
*/
|
|
1
9
|
import { parse } from 'node:url';
|
|
2
10
|
import encodeUrl from 'encodeurl';
|
|
3
11
|
import debug from './debug.js';
|
|
12
|
+
/**
|
|
13
|
+
* Exposes the API to construct redirect routes
|
|
14
|
+
*/
|
|
4
15
|
export class Redirect {
|
|
16
|
+
/**
|
|
17
|
+
* A boolean to forward the existing query string
|
|
18
|
+
*/
|
|
5
19
|
#forwardQueryString = false;
|
|
20
|
+
/**
|
|
21
|
+
* The status code for the redirect
|
|
22
|
+
*/
|
|
6
23
|
#statusCode = 302;
|
|
24
|
+
/**
|
|
25
|
+
* A custom query string to forward
|
|
26
|
+
*/
|
|
7
27
|
#queryString = {};
|
|
8
28
|
#request;
|
|
9
29
|
#response;
|
|
@@ -15,6 +35,9 @@ export class Redirect {
|
|
|
15
35
|
this.#router = router;
|
|
16
36
|
this.#qs = qs;
|
|
17
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Sends response by setting require headers
|
|
40
|
+
*/
|
|
18
41
|
#sendResponse(url, query) {
|
|
19
42
|
const stringified = this.#qs.stringify(query);
|
|
20
43
|
url = stringified ? `${url}?${stringified}` : url;
|
|
@@ -24,14 +47,24 @@ export class Redirect {
|
|
|
24
47
|
this.#response.type('text/plain; charset=utf-8');
|
|
25
48
|
this.#response.send(`Redirecting to ${url}`);
|
|
26
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Returns the referrer url
|
|
52
|
+
*/
|
|
27
53
|
#getReferrerUrl() {
|
|
28
54
|
let url = this.#request.headers['referer'] || this.#request.headers['referrer'] || '/';
|
|
29
55
|
return Array.isArray(url) ? url[0] : url;
|
|
30
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Set a custom status code.
|
|
59
|
+
*/
|
|
31
60
|
status(statusCode) {
|
|
32
61
|
this.#statusCode = statusCode;
|
|
33
62
|
return this;
|
|
34
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Clearing query string values added using the
|
|
66
|
+
* "withQs" method
|
|
67
|
+
*/
|
|
35
68
|
clearQs() {
|
|
36
69
|
this.#forwardQueryString = false;
|
|
37
70
|
this.#queryString = {};
|
|
@@ -49,18 +82,33 @@ export class Redirect {
|
|
|
49
82
|
Object.assign(this.#queryString, name);
|
|
50
83
|
return this;
|
|
51
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Redirect to the previous path.
|
|
87
|
+
*/
|
|
52
88
|
back() {
|
|
53
89
|
let query = {};
|
|
54
90
|
const referrerUrl = this.#getReferrerUrl();
|
|
55
91
|
const url = parse(referrerUrl);
|
|
56
92
|
debug('referrer url "%s"', referrerUrl);
|
|
57
93
|
debug('referrer base url "%s"', url.pathname);
|
|
94
|
+
/**
|
|
95
|
+
* Parse query string from the referrer url
|
|
96
|
+
*/
|
|
58
97
|
if (this.#forwardQueryString) {
|
|
59
98
|
query = this.#qs.parse(url.query || '');
|
|
60
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Append custom query string
|
|
102
|
+
*/
|
|
61
103
|
Object.assign(query, this.#queryString);
|
|
104
|
+
/**
|
|
105
|
+
* Redirect
|
|
106
|
+
*/
|
|
62
107
|
this.#sendResponse(url.pathname || '', query);
|
|
63
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Redirect the request using a route identifier.
|
|
111
|
+
*/
|
|
64
112
|
toRoute(routeIdentifier, params, options) {
|
|
65
113
|
if (options && options.qs) {
|
|
66
114
|
this.withQs(options.qs);
|
|
@@ -69,12 +117,24 @@ export class Redirect {
|
|
|
69
117
|
const url = this.#router.makeUrl(routeIdentifier, params, options);
|
|
70
118
|
return this.toPath(url);
|
|
71
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Redirect the request using a path.
|
|
122
|
+
*/
|
|
72
123
|
toPath(url) {
|
|
73
124
|
let query = {};
|
|
125
|
+
/**
|
|
126
|
+
* Extract query string from the current URL
|
|
127
|
+
*/
|
|
74
128
|
if (this.#forwardQueryString) {
|
|
75
129
|
query = this.#qs.parse(parse(this.#request.url).query || '');
|
|
76
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Assign custom query string
|
|
133
|
+
*/
|
|
77
134
|
Object.assign(query, this.#queryString);
|
|
135
|
+
/**
|
|
136
|
+
* Redirect
|
|
137
|
+
*/
|
|
78
138
|
this.#sendResponse(url, query);
|
|
79
139
|
}
|
|
80
140
|
}
|