@adonisjs/http-server 5.7.4 → 5.8.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.
|
@@ -350,6 +350,7 @@ declare module '@ioc:Adonis/Core/Route' {
|
|
|
350
350
|
qs?: Record<string, any>;
|
|
351
351
|
domain?: string;
|
|
352
352
|
prefixUrl?: string;
|
|
353
|
+
disableRouteLookup?: boolean;
|
|
353
354
|
} & Record<string, any>;
|
|
354
355
|
/**
|
|
355
356
|
* Options for making a signed url
|
|
@@ -518,6 +519,11 @@ declare module '@ioc:Adonis/Core/Route' {
|
|
|
518
519
|
* Generate url for the given route
|
|
519
520
|
*/
|
|
520
521
|
make(identifier: string): string;
|
|
522
|
+
/**
|
|
523
|
+
* Disable route lookup and consider identifier
|
|
524
|
+
* as the route pattern
|
|
525
|
+
*/
|
|
526
|
+
disableRouteLookup(): this;
|
|
521
527
|
/**
|
|
522
528
|
* Generate signed url for the given route
|
|
523
529
|
*/
|
|
@@ -14,6 +14,11 @@ export declare class UrlBuilder implements UrlBuilderContract {
|
|
|
14
14
|
* A custom query string to append to the URL
|
|
15
15
|
*/
|
|
16
16
|
private queryString;
|
|
17
|
+
/**
|
|
18
|
+
* A boolean to know if the route should be looked
|
|
19
|
+
* up inside the route store or not
|
|
20
|
+
*/
|
|
21
|
+
private lookupRoute;
|
|
17
22
|
/**
|
|
18
23
|
* A baseUrl to prefix to the endpoint
|
|
19
24
|
*/
|
|
@@ -36,6 +41,11 @@ export declare class UrlBuilder implements UrlBuilderContract {
|
|
|
36
41
|
* Prefix a custom url to the final URI
|
|
37
42
|
*/
|
|
38
43
|
prefixUrl(url: string): this;
|
|
44
|
+
/**
|
|
45
|
+
* Disable route lookup. Calling this method considers
|
|
46
|
+
* the "identifier" as the route pattern
|
|
47
|
+
*/
|
|
48
|
+
disableRouteLookup(): this;
|
|
39
49
|
/**
|
|
40
50
|
* Append query string to the final URI
|
|
41
51
|
*/
|
|
@@ -26,6 +26,11 @@ class UrlBuilder {
|
|
|
26
26
|
* A custom query string to append to the URL
|
|
27
27
|
*/
|
|
28
28
|
this.queryString = {};
|
|
29
|
+
/**
|
|
30
|
+
* A boolean to know if the route should be looked
|
|
31
|
+
* up inside the route store or not
|
|
32
|
+
*/
|
|
33
|
+
this.lookupRoute = true;
|
|
29
34
|
}
|
|
30
35
|
/**
|
|
31
36
|
* Processes the pattern against the params
|
|
@@ -105,6 +110,14 @@ class UrlBuilder {
|
|
|
105
110
|
this.baseUrl = url;
|
|
106
111
|
return this;
|
|
107
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* Disable route lookup. Calling this method considers
|
|
115
|
+
* the "identifier" as the route pattern
|
|
116
|
+
*/
|
|
117
|
+
disableRouteLookup() {
|
|
118
|
+
this.lookupRoute = false;
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
108
121
|
/**
|
|
109
122
|
* Append query string to the final URI
|
|
110
123
|
*/
|
|
@@ -129,16 +142,28 @@ class UrlBuilder {
|
|
|
129
142
|
* Generate url for the given route identifier
|
|
130
143
|
*/
|
|
131
144
|
make(identifier) {
|
|
132
|
-
|
|
133
|
-
|
|
145
|
+
let url;
|
|
146
|
+
if (this.lookupRoute) {
|
|
147
|
+
const route = this.findRouteOrFail(identifier);
|
|
148
|
+
url = this.processPattern(route.pattern);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
url = this.processPattern(identifier);
|
|
152
|
+
}
|
|
134
153
|
return this.suffixQueryString(this.baseUrl ? `${this.baseUrl}${url}` : url);
|
|
135
154
|
}
|
|
136
155
|
/**
|
|
137
156
|
* Generate url for the given route identifier
|
|
138
157
|
*/
|
|
139
158
|
makeSigned(identifier, options) {
|
|
140
|
-
|
|
141
|
-
|
|
159
|
+
let url;
|
|
160
|
+
if (this.lookupRoute) {
|
|
161
|
+
const route = this.findRouteOrFail(identifier);
|
|
162
|
+
url = this.processPattern(route.pattern);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
url = this.processPattern(identifier);
|
|
166
|
+
}
|
|
142
167
|
/*
|
|
143
168
|
* Making the signature from the qualified url. We do not prefix the domain when
|
|
144
169
|
* making signature, since it just makes the signature big.
|
|
@@ -327,6 +327,7 @@ class Router {
|
|
|
327
327
|
normalizedOptions.params && builder.params(normalizedOptions.params);
|
|
328
328
|
normalizedOptions.qs && builder.qs(normalizedOptions.qs);
|
|
329
329
|
normalizedOptions.prefixUrl && builder.prefixUrl(normalizedOptions.prefixUrl);
|
|
330
|
+
normalizedOptions.disableRouteLookup && builder.disableRouteLookup();
|
|
330
331
|
return builder.make(routeIdentifier);
|
|
331
332
|
}
|
|
332
333
|
/**
|
|
@@ -341,6 +342,7 @@ class Router {
|
|
|
341
342
|
normalizedOptions.params && builder.params(normalizedOptions.params);
|
|
342
343
|
normalizedOptions.qs && builder.qs(normalizedOptions.qs);
|
|
343
344
|
normalizedOptions.prefixUrl && builder.prefixUrl(normalizedOptions.prefixUrl);
|
|
345
|
+
normalizedOptions.disableRouteLookup && builder.disableRouteLookup();
|
|
344
346
|
return builder.makeSigned(routeIdentifier, normalizedOptions);
|
|
345
347
|
}
|
|
346
348
|
}
|
package/build/src/helpers.d.ts
CHANGED
|
@@ -48,6 +48,7 @@ export declare function normalizeMakeUrlOptions(params?: any[] | MakeUrlOptions,
|
|
|
48
48
|
qs: any;
|
|
49
49
|
domain: string | undefined;
|
|
50
50
|
prefixUrl: string | undefined;
|
|
51
|
+
disableRouteLookup: boolean;
|
|
51
52
|
};
|
|
52
53
|
/**
|
|
53
54
|
* Normalizes the make signed url options by allowing params to appear on
|
|
@@ -60,6 +61,7 @@ export declare function normalizeMakeSignedUrlOptions(params?: any[] | MakeSigne
|
|
|
60
61
|
prefixUrl: string | undefined;
|
|
61
62
|
expiresIn: any;
|
|
62
63
|
purpose: any;
|
|
64
|
+
disableRouteLookup: boolean;
|
|
63
65
|
};
|
|
64
66
|
/**
|
|
65
67
|
* Wraps `fs.stat` to promise interface.
|
package/build/src/helpers.js
CHANGED
|
@@ -143,13 +143,14 @@ function normalizeMakeUrlOptions(params, options) {
|
|
|
143
143
|
const qs = options.qs || params['qs'];
|
|
144
144
|
const domain = options.domain;
|
|
145
145
|
const prefixUrl = options.prefixUrl;
|
|
146
|
+
const disableRouteLookup = options.disableRouteLookup || false;
|
|
146
147
|
/**
|
|
147
148
|
* Using legacy options
|
|
148
149
|
*/
|
|
149
150
|
onIntersect(params, ['prefixDomain', 'domainParams', 'qs', 'params'], () => {
|
|
150
151
|
process.emitWarning('DeprecationWarning', 'You are using legacy the API of the "Route.makeUrl". We recommend reading the docs and use the latest API');
|
|
151
152
|
});
|
|
152
|
-
return { params: normalizedParams, qs, domain, prefixUrl };
|
|
153
|
+
return { params: normalizedParams, qs, domain, prefixUrl, disableRouteLookup };
|
|
153
154
|
}
|
|
154
155
|
exports.normalizeMakeUrlOptions = normalizeMakeUrlOptions;
|
|
155
156
|
/**
|
|
@@ -168,13 +169,14 @@ function normalizeMakeSignedUrlOptions(params, options) {
|
|
|
168
169
|
const purpose = options.purpose || params['purpose'];
|
|
169
170
|
const domain = options.domain;
|
|
170
171
|
const prefixUrl = options.prefixUrl;
|
|
172
|
+
const disableRouteLookup = options.disableRouteLookup || false;
|
|
171
173
|
/**
|
|
172
174
|
* Using legacy options
|
|
173
175
|
*/
|
|
174
176
|
onIntersect(params, ['prefixDomain', 'domainParams', 'qs', 'params', 'purpose', 'expiresIn'], () => {
|
|
175
177
|
process.emitWarning('DeprecationWarning', 'You are using legacy the API of the "Route.makeSignedUrl". We recommend reading the docs and use the latest API');
|
|
176
178
|
});
|
|
177
|
-
return { params: normalizedParams, qs, domain, prefixUrl, expiresIn, purpose };
|
|
179
|
+
return { params: normalizedParams, qs, domain, prefixUrl, expiresIn, purpose, disableRouteLookup };
|
|
178
180
|
}
|
|
179
181
|
exports.normalizeMakeSignedUrlOptions = normalizeMakeSignedUrlOptions;
|
|
180
182
|
/**
|