@adonisjs/http-server 7.0.0-0 → 7.0.0-2
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 → chunk-Z63E3STR.js} +66 -18
- package/build/chunk-Z63E3STR.js.map +1 -0
- package/build/factories/http_context.d.ts +25 -0
- package/build/factories/http_server.d.ts +8 -0
- package/build/factories/main.d.ts +6 -149
- package/build/factories/main.js +2 -1
- package/build/factories/main.js.map +1 -0
- package/build/factories/qs_parser_factory.d.ts +20 -0
- package/build/factories/request.d.ts +29 -0
- package/build/factories/response.d.ts +29 -0
- package/build/factories/router.d.ts +23 -0
- package/build/factories/server_factory.d.ts +29 -0
- package/build/index.d.ts +14 -272
- package/build/index.js +2 -1
- package/build/index.js.map +1 -0
- package/build/src/cookies/client.d.ts +37 -0
- package/build/src/cookies/drivers/encrypted.d.ts +16 -0
- package/build/src/cookies/drivers/plain.d.ts +15 -0
- package/build/src/cookies/drivers/signed.d.ts +16 -0
- package/build/src/cookies/parser.d.ts +37 -0
- package/build/src/cookies/serializer.d.ts +33 -0
- package/build/src/debug.d.ts +3 -0
- package/build/src/define_config.d.ts +9 -0
- package/build/src/define_middleware.d.ts +11 -0
- package/build/src/exception_handler.d.ts +113 -0
- package/build/src/exceptions.d.ts +84 -0
- package/build/src/helpers.d.ts +23 -0
- package/build/src/http_context/local_storage.d.ts +12 -0
- package/build/src/http_context/main.d.ts +58 -0
- package/build/src/qs.d.ts +11 -0
- package/build/src/redirect.d.ts +42 -0
- package/build/src/request.d.ts +565 -0
- package/build/src/response.d.ts +620 -0
- package/build/src/router/brisk.d.ts +42 -0
- package/build/src/router/executor.d.ts +9 -0
- package/build/src/router/factories/use_return_value.d.ts +6 -0
- package/build/src/router/group.d.ts +65 -0
- package/build/src/router/lookup_store/main.d.ts +47 -0
- package/build/src/router/lookup_store/route_finder.d.ts +25 -0
- package/build/src/router/lookup_store/url_builder.d.ts +52 -0
- package/build/src/router/main.d.ts +128 -0
- package/build/src/router/matchers.d.ts +27 -0
- package/build/src/router/parser.d.ts +5 -0
- package/build/src/router/resource.d.ts +66 -0
- package/build/src/router/route.d.ts +92 -0
- package/build/src/router/store.d.ts +66 -0
- package/build/src/server/factories/final_handler.d.ts +10 -0
- package/build/src/server/factories/middleware_handler.d.ts +8 -0
- package/build/src/server/factories/write_response.d.ts +6 -0
- package/build/{main-29eaaee4.d.ts → src/server/main.d.ts} +18 -13
- package/build/src/types/base.d.ts +19 -0
- package/build/src/types/main.d.ts +7 -14
- package/build/src/types/main.js +1 -0
- package/build/src/types/main.js.map +1 -0
- package/build/src/types/middleware.d.ts +35 -0
- package/build/src/types/qs.d.ts +68 -0
- package/build/src/types/request.d.ts +39 -0
- package/build/src/types/response.d.ts +45 -0
- package/build/src/types/route.d.ts +166 -0
- package/build/src/types/server.d.ts +72 -0
- package/package.json +52 -48
- package/build/main-e5b46c83.d.ts +0 -2210
package/build/main-e5b46c83.d.ts
DELETED
|
@@ -1,2210 +0,0 @@
|
|
|
1
|
-
import { ContainerResolver } from '@adonisjs/fold';
|
|
2
|
-
import Macroable from '@poppinss/macroable';
|
|
3
|
-
import { Logger } from '@adonisjs/logger';
|
|
4
|
-
import { UrlWithStringQuery } from 'node:url';
|
|
5
|
-
import { Encryption } from '@adonisjs/encryption';
|
|
6
|
-
import { IncomingMessage, ServerResponse, IncomingHttpHeaders } from 'node:http';
|
|
7
|
-
import * as qs from 'qs';
|
|
8
|
-
import * as http from 'http';
|
|
9
|
-
import * as stream from 'stream';
|
|
10
|
-
import Middleware from '@poppinss/middleware';
|
|
11
|
-
import { NextFn, FinalHandler, ErrorHandler } from '@poppinss/middleware/types';
|
|
12
|
-
import { Readable } from 'node:stream';
|
|
13
|
-
import { Application } from '@adonisjs/application';
|
|
14
|
-
|
|
15
|
-
type QSParserConfig = {
|
|
16
|
-
parse: {
|
|
17
|
-
/**
|
|
18
|
-
* Nesting depth till the parameters should be parsed.
|
|
19
|
-
*
|
|
20
|
-
* Defaults to 5
|
|
21
|
-
*/
|
|
22
|
-
depth: number;
|
|
23
|
-
/**
|
|
24
|
-
* Number of parameters to parse.
|
|
25
|
-
*
|
|
26
|
-
* Defaults to 1000
|
|
27
|
-
*/
|
|
28
|
-
parameterLimit: number;
|
|
29
|
-
/**
|
|
30
|
-
* Allow sparse elements in an array.
|
|
31
|
-
*
|
|
32
|
-
* Defaults to false
|
|
33
|
-
*/
|
|
34
|
-
allowSparse: boolean;
|
|
35
|
-
/**
|
|
36
|
-
* The max limimit for the array indices. After the given limit
|
|
37
|
-
* the array indices will be converted to an object, where the
|
|
38
|
-
* index is the key.
|
|
39
|
-
*
|
|
40
|
-
* Defaults to 20
|
|
41
|
-
*/
|
|
42
|
-
arrayLimit: number;
|
|
43
|
-
/**
|
|
44
|
-
* Join comma seperated query string values to an array
|
|
45
|
-
*
|
|
46
|
-
* Defaults to false
|
|
47
|
-
*/
|
|
48
|
-
comma: boolean;
|
|
49
|
-
};
|
|
50
|
-
stringify: {
|
|
51
|
-
/**
|
|
52
|
-
* URI encode the stringified query string
|
|
53
|
-
*
|
|
54
|
-
* Defaults to true
|
|
55
|
-
*/
|
|
56
|
-
encode: boolean;
|
|
57
|
-
/**
|
|
58
|
-
* URI encode but only the values and not the keys
|
|
59
|
-
*
|
|
60
|
-
* Defaults to false
|
|
61
|
-
*/
|
|
62
|
-
encodeValuesOnly: boolean;
|
|
63
|
-
/**
|
|
64
|
-
* Define the format in which arrays should be serialized.
|
|
65
|
-
*
|
|
66
|
-
* - indices: a[0]=b&a[1]=c
|
|
67
|
-
* - brackets: a[]=b&a[]=c
|
|
68
|
-
* - repeat: a=b&a=c
|
|
69
|
-
* - comma: a=b,c
|
|
70
|
-
*
|
|
71
|
-
* Defaults to "indices"
|
|
72
|
-
*/
|
|
73
|
-
arrayFormat: 'indices' | 'brackets' | 'repeat' | 'comma';
|
|
74
|
-
/**
|
|
75
|
-
* Whether or not to skip null values when serializing. When set to
|
|
76
|
-
* false, the null values will be treated as an empty string.
|
|
77
|
-
*
|
|
78
|
-
* Defaults to: false
|
|
79
|
-
*/
|
|
80
|
-
skipNulls: boolean;
|
|
81
|
-
};
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Query string parser used to parse and stringify query
|
|
86
|
-
* strings.
|
|
87
|
-
*/
|
|
88
|
-
declare class Qs {
|
|
89
|
-
#private;
|
|
90
|
-
constructor(config: QSParserConfig);
|
|
91
|
-
parse(value: string): qs.ParsedQs;
|
|
92
|
-
stringify(value: any): string;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Shape of the request config
|
|
97
|
-
*/
|
|
98
|
-
type RequestConfig = {
|
|
99
|
-
/**
|
|
100
|
-
* URL segments to ignore when extracting subdomains from a URL.
|
|
101
|
-
* Defaults to 2
|
|
102
|
-
*/
|
|
103
|
-
subdomainOffset: number;
|
|
104
|
-
/**
|
|
105
|
-
* Enabling the flag will generated a unique request id from every
|
|
106
|
-
* HTTP request.
|
|
107
|
-
*
|
|
108
|
-
* The request id can be accessed using the "request.id()" method. Also,
|
|
109
|
-
* the value of `x-request-id` header is used as the id (if it exists).
|
|
110
|
-
*
|
|
111
|
-
* Defaults to false
|
|
112
|
-
*/
|
|
113
|
-
generateRequestId: boolean;
|
|
114
|
-
/**
|
|
115
|
-
* Method spoofing allows changing the request method using the query string.
|
|
116
|
-
* For example: Making a POST request on URL /users/1?_method=PATCH will
|
|
117
|
-
* be handled by the patch route.
|
|
118
|
-
*
|
|
119
|
-
* Defaults to false
|
|
120
|
-
*/
|
|
121
|
-
allowMethodSpoofing: boolean;
|
|
122
|
-
/**
|
|
123
|
-
* A custom implementation to get the request ip address
|
|
124
|
-
*/
|
|
125
|
-
getIp?: (request: any) => string;
|
|
126
|
-
/**
|
|
127
|
-
* A callback function to trust proxy ip addresses. You must use
|
|
128
|
-
* the `proxy-addr` package to compute this value.
|
|
129
|
-
*
|
|
130
|
-
* Defaults to: "proxyAddr.compile('loopback')"
|
|
131
|
-
*/
|
|
132
|
-
trustProxy: (address: string, distance: number) => boolean;
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Accept one or more of the mentioned type
|
|
137
|
-
*/
|
|
138
|
-
type OneOrMore<T> = T | T[];
|
|
139
|
-
/**
|
|
140
|
-
* Class constructor type
|
|
141
|
-
*/
|
|
142
|
-
type Constructor<T> = new (...args: any[]) => T;
|
|
143
|
-
/**
|
|
144
|
-
* A function that lazily imports a middleware
|
|
145
|
-
*/
|
|
146
|
-
type LazyImport<DefaultExport> = () => Promise<{
|
|
147
|
-
default: DefaultExport;
|
|
148
|
-
}>;
|
|
149
|
-
/**
|
|
150
|
-
* Unwraps default export from a lazy import function
|
|
151
|
-
*/
|
|
152
|
-
type UnWrapLazyImport<Fn extends LazyImport<any>> = Awaited<ReturnType<Fn>>['default'];
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Middleware represented as a class
|
|
156
|
-
*/
|
|
157
|
-
type MiddlewareAsClass = Constructor<{
|
|
158
|
-
handle: (ctx: HttpContext, next: NextFn, args?: any) => any;
|
|
159
|
-
}>;
|
|
160
|
-
/**
|
|
161
|
-
* Check if a union has undefined or null
|
|
162
|
-
*/
|
|
163
|
-
type HasUndefined<T> = T extends NonNullable<T> ? true : false;
|
|
164
|
-
/**
|
|
165
|
-
* Returns the arguments accepted by the middleware's handle method
|
|
166
|
-
*/
|
|
167
|
-
type GetMiddlewareArgs<Middleware extends MiddlewareAsClass> = Parameters<InstanceType<Middleware>['handle']>[2] extends undefined ? [] : HasUndefined<Parameters<InstanceType<Middleware>['handle']>[2]> extends true ? [Parameters<InstanceType<Middleware>['handle']>[2]] : [Parameters<InstanceType<Middleware>['handle']>[2]?];
|
|
168
|
-
/**
|
|
169
|
-
* The middleware defined as a function on the router or the server
|
|
170
|
-
*/
|
|
171
|
-
type MiddlewareFn = (ctx: HttpContext, next: NextFn) => any;
|
|
172
|
-
/**
|
|
173
|
-
* Parsed global middleware
|
|
174
|
-
*/
|
|
175
|
-
type ParsedGlobalMiddleware = {
|
|
176
|
-
handle: (resolver: ContainerResolver<any>, ...args: [ctx: HttpContext, next: NextFn, params?: any]) => any;
|
|
177
|
-
};
|
|
178
|
-
/**
|
|
179
|
-
* Parsed named middleware
|
|
180
|
-
*/
|
|
181
|
-
type ParsedNamedMiddleware = ParsedGlobalMiddleware & {
|
|
182
|
-
name: string;
|
|
183
|
-
args: any;
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Cookie options can that can be set on the response
|
|
188
|
-
*/
|
|
189
|
-
type CookieOptions = {
|
|
190
|
-
domain: string;
|
|
191
|
-
expires: Date | (() => Date);
|
|
192
|
-
httpOnly: boolean;
|
|
193
|
-
maxAge: number | string;
|
|
194
|
-
path: string;
|
|
195
|
-
sameSite: boolean | 'lax' | 'none' | 'strict';
|
|
196
|
-
secure: boolean;
|
|
197
|
-
};
|
|
198
|
-
/**
|
|
199
|
-
* Types from which response header can be casted to a
|
|
200
|
-
* string
|
|
201
|
-
*/
|
|
202
|
-
type CastableHeader = string | number | boolean | string[] | number[] | boolean[];
|
|
203
|
-
/**
|
|
204
|
-
* Config accepted by response the class
|
|
205
|
-
*/
|
|
206
|
-
type ResponseConfig = {
|
|
207
|
-
/**
|
|
208
|
-
* Whether or not to generate etags for responses. Etags can be
|
|
209
|
-
* enabled/disabled when sending response as well.
|
|
210
|
-
*
|
|
211
|
-
* Defaults to false
|
|
212
|
-
*/
|
|
213
|
-
etag: boolean;
|
|
214
|
-
/**
|
|
215
|
-
* The callback name for the JSONP response.
|
|
216
|
-
*
|
|
217
|
-
* Defaults to 'callback'
|
|
218
|
-
*/
|
|
219
|
-
jsonpCallbackName: string;
|
|
220
|
-
/**
|
|
221
|
-
* Options to set cookies
|
|
222
|
-
*/
|
|
223
|
-
cookie: Partial<CookieOptions>;
|
|
224
|
-
};
|
|
225
|
-
/**
|
|
226
|
-
* Stream that can be piped to the "response.stream" method
|
|
227
|
-
*/
|
|
228
|
-
type ResponseStream = Readable;
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Normalized HTTP error used by the exception
|
|
232
|
-
* handler.
|
|
233
|
-
*/
|
|
234
|
-
type HttpError = {
|
|
235
|
-
message: string;
|
|
236
|
-
status: number;
|
|
237
|
-
code?: string;
|
|
238
|
-
stack?: string;
|
|
239
|
-
cause?: any;
|
|
240
|
-
messages?: any;
|
|
241
|
-
errors?: any;
|
|
242
|
-
handle?: (...args: any[]) => any;
|
|
243
|
-
report?: (...args: any[]) => any;
|
|
244
|
-
};
|
|
245
|
-
/**
|
|
246
|
-
* The pipeline for executing middleware during tests
|
|
247
|
-
*/
|
|
248
|
-
interface TestingMiddlewarePipeline {
|
|
249
|
-
finalHandler(handler: FinalHandler): this;
|
|
250
|
-
errorHandler(handler: ErrorHandler): this;
|
|
251
|
-
run(ctx: HttpContext): Promise<any>;
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* The expression to define a status page range
|
|
255
|
-
*/
|
|
256
|
-
type StatusPageRange = `${number}..${number}` | `${number}` | number;
|
|
257
|
-
/**
|
|
258
|
-
* The callback function to render status page for a given
|
|
259
|
-
* error.
|
|
260
|
-
*/
|
|
261
|
-
type StatusPageRenderer = (error: HttpError, ctx: HttpContext) => any | Promise<any>;
|
|
262
|
-
/**
|
|
263
|
-
* Data type for the "http:request_finished" event
|
|
264
|
-
*/
|
|
265
|
-
type HttpRequestFinishedPayload = {
|
|
266
|
-
ctx: HttpContext;
|
|
267
|
-
duration: [number, number];
|
|
268
|
-
};
|
|
269
|
-
/**
|
|
270
|
-
* Error handler to handle HTTP errors
|
|
271
|
-
*/
|
|
272
|
-
type ServerErrorHandler = {
|
|
273
|
-
report: (error: any, ctx: HttpContext) => any;
|
|
274
|
-
handle: (error: any, ctx: HttpContext) => any;
|
|
275
|
-
};
|
|
276
|
-
/**
|
|
277
|
-
* Error handler represented as a class
|
|
278
|
-
*/
|
|
279
|
-
type ErrorHandlerAsAClass = Constructor<ServerErrorHandler>;
|
|
280
|
-
/**
|
|
281
|
-
* Config accepted by the HTTP server
|
|
282
|
-
*/
|
|
283
|
-
type ServerConfig = RequestConfig & ResponseConfig & {
|
|
284
|
-
/**
|
|
285
|
-
* Whether or not to create an async local storage store for
|
|
286
|
-
* the HTTP context.
|
|
287
|
-
*
|
|
288
|
-
* Defaults to false
|
|
289
|
-
*/
|
|
290
|
-
useAsyncLocalStorage: boolean;
|
|
291
|
-
/**
|
|
292
|
-
* Config for query string parser
|
|
293
|
-
*/
|
|
294
|
-
qs: QSParserConfig;
|
|
295
|
-
};
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* Returns a union of methods from a controller that accepts
|
|
299
|
-
* the context as the first argument.
|
|
300
|
-
*/
|
|
301
|
-
type GetControllerHandlers<Controller extends Constructor<any>> = {
|
|
302
|
-
[K in keyof InstanceType<Controller>]: InstanceType<Controller>[K] extends (ctx: HttpContext, ...args: any[]) => any ? K : never;
|
|
303
|
-
}[keyof InstanceType<Controller>];
|
|
304
|
-
/**
|
|
305
|
-
* Route token stored by matchit library
|
|
306
|
-
*/
|
|
307
|
-
type MatchItRouteToken = RouteMatcher & {
|
|
308
|
-
old: string;
|
|
309
|
-
type: 0 | 1 | 2 | 3;
|
|
310
|
-
val: string;
|
|
311
|
-
end: string;
|
|
312
|
-
};
|
|
313
|
-
/**
|
|
314
|
-
* Route handler defined as a function
|
|
315
|
-
*/
|
|
316
|
-
type RouteFn = (ctx: HttpContext) => any;
|
|
317
|
-
/**
|
|
318
|
-
* Route handler persisted with the route store
|
|
319
|
-
*/
|
|
320
|
-
type StoreRouteHandler = RouteFn | {
|
|
321
|
-
reference: string | [LazyImport<Constructor<any>> | Constructor<any>, any?];
|
|
322
|
-
handle: (resolver: ContainerResolver<any>, ...args: [ctx: HttpContext, ...injections: any[]]) => any;
|
|
323
|
-
};
|
|
324
|
-
/**
|
|
325
|
-
* The middleware persisted with the route store
|
|
326
|
-
*/
|
|
327
|
-
type StoreRouteMiddleware = MiddlewareFn | ({
|
|
328
|
-
name?: string;
|
|
329
|
-
args?: any[];
|
|
330
|
-
} & ParsedGlobalMiddleware);
|
|
331
|
-
/**
|
|
332
|
-
* Route node persisted within the routes store
|
|
333
|
-
*/
|
|
334
|
-
type StoreRouteNode = {
|
|
335
|
-
/**
|
|
336
|
-
* The execute function to execute the route middleware
|
|
337
|
-
* and the handler
|
|
338
|
-
*/
|
|
339
|
-
execute: (route: StoreRouteNode, resolver: ContainerResolver<any>, ctx: HttpContext, errorResponder: ServerErrorHandler['handle']) => any;
|
|
340
|
-
/**
|
|
341
|
-
* A unique name for the route
|
|
342
|
-
*/
|
|
343
|
-
name?: string;
|
|
344
|
-
/**
|
|
345
|
-
* Route URI pattern
|
|
346
|
-
*/
|
|
347
|
-
pattern: string;
|
|
348
|
-
/**
|
|
349
|
-
* Route handler
|
|
350
|
-
*/
|
|
351
|
-
handler: StoreRouteHandler;
|
|
352
|
-
/**
|
|
353
|
-
* Route middleware
|
|
354
|
-
*/
|
|
355
|
-
middleware: Middleware<StoreRouteMiddleware>;
|
|
356
|
-
/**
|
|
357
|
-
* Additional metadata associated with the route
|
|
358
|
-
*/
|
|
359
|
-
meta: Record<string, any>;
|
|
360
|
-
};
|
|
361
|
-
/**
|
|
362
|
-
* An object of routes for a given HTTP method
|
|
363
|
-
*/
|
|
364
|
-
type StoreMethodNode = {
|
|
365
|
-
tokens: MatchItRouteToken[][];
|
|
366
|
-
routeKeys: {
|
|
367
|
-
[pattern: string]: string;
|
|
368
|
-
};
|
|
369
|
-
routes: {
|
|
370
|
-
[pattern: string]: StoreRouteNode;
|
|
371
|
-
};
|
|
372
|
-
};
|
|
373
|
-
/**
|
|
374
|
-
* Each domain node container an object of methods. Each method
|
|
375
|
-
* object has nested routes.
|
|
376
|
-
*/
|
|
377
|
-
type StoreDomainNode = {
|
|
378
|
-
[method: string]: StoreMethodNode;
|
|
379
|
-
};
|
|
380
|
-
/**
|
|
381
|
-
* Routes tree stored within the routes store
|
|
382
|
-
*/
|
|
383
|
-
type StoreRoutesTree = {
|
|
384
|
-
tokens: MatchItRouteToken[][];
|
|
385
|
-
domains: {
|
|
386
|
-
[domain: string]: StoreDomainNode;
|
|
387
|
-
};
|
|
388
|
-
};
|
|
389
|
-
/**
|
|
390
|
-
* Shape of the matched route for a pattern, method and domain.
|
|
391
|
-
*/
|
|
392
|
-
type MatchedRoute = {
|
|
393
|
-
route: StoreRouteNode;
|
|
394
|
-
/**
|
|
395
|
-
* A unique key for the looked up route
|
|
396
|
-
*/
|
|
397
|
-
routeKey: string;
|
|
398
|
-
/**
|
|
399
|
-
* Route params
|
|
400
|
-
*/
|
|
401
|
-
params: Record<string, any>;
|
|
402
|
-
/**
|
|
403
|
-
* Route subdomains (if part of a subdomain)
|
|
404
|
-
*/
|
|
405
|
-
subdomains: Record<string, any>;
|
|
406
|
-
};
|
|
407
|
-
/**
|
|
408
|
-
* Shape of a route param matcher
|
|
409
|
-
*/
|
|
410
|
-
type RouteMatcher = {
|
|
411
|
-
match?: RegExp;
|
|
412
|
-
cast?: (value: string) => any;
|
|
413
|
-
};
|
|
414
|
-
/**
|
|
415
|
-
* A collection of route matchers
|
|
416
|
-
*/
|
|
417
|
-
type RouteMatchers$1 = {
|
|
418
|
-
[param: string]: RouteMatcher;
|
|
419
|
-
};
|
|
420
|
-
/**
|
|
421
|
-
* Representation of a route as JSON
|
|
422
|
-
*/
|
|
423
|
-
type RouteJSON = StoreRouteNode & {
|
|
424
|
-
/**
|
|
425
|
-
* HTTP methods, the route responds to.
|
|
426
|
-
*/
|
|
427
|
-
methods: string[];
|
|
428
|
-
/**
|
|
429
|
-
* The domain for which the route is registered.
|
|
430
|
-
*/
|
|
431
|
-
domain: string;
|
|
432
|
-
/**
|
|
433
|
-
* Matchers for route params.
|
|
434
|
-
*/
|
|
435
|
-
matchers: RouteMatchers$1;
|
|
436
|
-
};
|
|
437
|
-
/**
|
|
438
|
-
* Resource action names
|
|
439
|
-
*/
|
|
440
|
-
type ResourceActionNames = 'create' | 'index' | 'store' | 'show' | 'edit' | 'update' | 'destroy';
|
|
441
|
-
/**
|
|
442
|
-
* Options accepted by makeUrl method
|
|
443
|
-
*/
|
|
444
|
-
type MakeUrlOptions = {
|
|
445
|
-
qs?: Record<string, any>;
|
|
446
|
-
domain?: string;
|
|
447
|
-
prefixUrl?: string;
|
|
448
|
-
disableRouteLookup?: boolean;
|
|
449
|
-
};
|
|
450
|
-
/**
|
|
451
|
-
* Options accepted by makeSignedUrl method
|
|
452
|
-
*/
|
|
453
|
-
type MakeSignedUrlOptions = MakeUrlOptions & {
|
|
454
|
-
expiresIn?: string | number;
|
|
455
|
-
purpose?: string;
|
|
456
|
-
};
|
|
457
|
-
|
|
458
|
-
/**
|
|
459
|
-
* The route class exposes the APIs for constructing a route using the
|
|
460
|
-
* fluent API.
|
|
461
|
-
*/
|
|
462
|
-
declare class Route<Controller extends Constructor<any> = any> extends Macroable {
|
|
463
|
-
#private;
|
|
464
|
-
constructor(app: Application<any>, routerMiddleware: ParsedGlobalMiddleware[], options: {
|
|
465
|
-
pattern: string;
|
|
466
|
-
methods: string[];
|
|
467
|
-
handler: RouteFn | string | [LazyImport<Controller> | Controller, GetControllerHandlers<Controller>?];
|
|
468
|
-
globalMatchers: RouteMatchers$1;
|
|
469
|
-
});
|
|
470
|
-
/**
|
|
471
|
-
* Define matcher for a given param. If a matcher exists, then we do not
|
|
472
|
-
* override that, since the routes inside a group will set matchers
|
|
473
|
-
* before the group, so they should have priority over the group
|
|
474
|
-
* matchers.
|
|
475
|
-
*
|
|
476
|
-
* ```ts
|
|
477
|
-
* Route.group(() => {
|
|
478
|
-
* Route.get('/:id', 'handler').where('id', /^[0-9]$/)
|
|
479
|
-
* }).where('id', /[^a-z$]/)
|
|
480
|
-
* ```
|
|
481
|
-
*
|
|
482
|
-
* The `/^[0-9]$/` will win over the matcher defined by the group
|
|
483
|
-
*/
|
|
484
|
-
where(param: string, matcher: RouteMatcher | string | RegExp): this;
|
|
485
|
-
/**
|
|
486
|
-
* Define prefix for the route. Calling this method multiple times
|
|
487
|
-
* applies multiple prefixes in the reverse order.
|
|
488
|
-
*/
|
|
489
|
-
prefix(prefix: string): this;
|
|
490
|
-
/**
|
|
491
|
-
* Define a custom domain for the route. We do not overwrite the domain
|
|
492
|
-
* unless `overwrite` flag is set to true.
|
|
493
|
-
*/
|
|
494
|
-
domain(domain: string, overwrite?: boolean): this;
|
|
495
|
-
/**
|
|
496
|
-
* Define one or more middleware to be executed before the route
|
|
497
|
-
* handler.
|
|
498
|
-
*
|
|
499
|
-
* Named middleware can be referenced using the name registered with
|
|
500
|
-
* the router middleware store.
|
|
501
|
-
*/
|
|
502
|
-
use(middleware: OneOrMore<MiddlewareFn | ParsedNamedMiddleware>): this;
|
|
503
|
-
/**
|
|
504
|
-
* @alias use
|
|
505
|
-
*/
|
|
506
|
-
middleware(middleware: OneOrMore<MiddlewareFn | ParsedNamedMiddleware>): this;
|
|
507
|
-
/**
|
|
508
|
-
* Give a unique name to the route. Assinging a new unique removes the
|
|
509
|
-
* existing name of the route.
|
|
510
|
-
*
|
|
511
|
-
* Setting prepends to true prefixes the name to the existing name.
|
|
512
|
-
*/
|
|
513
|
-
as(name: string, prepend?: boolean): this;
|
|
514
|
-
/**
|
|
515
|
-
* Check if the route was marked to be deleted
|
|
516
|
-
*/
|
|
517
|
-
isDeleted(): boolean;
|
|
518
|
-
/**
|
|
519
|
-
* Mark route as deleted. Deleted routes are not registered
|
|
520
|
-
* with the route store
|
|
521
|
-
*/
|
|
522
|
-
markAsDeleted(): void;
|
|
523
|
-
/**
|
|
524
|
-
* Get the route name
|
|
525
|
-
*/
|
|
526
|
-
getName(): string | undefined;
|
|
527
|
-
/**
|
|
528
|
-
* Get the route pattern
|
|
529
|
-
*/
|
|
530
|
-
getPattern(): string;
|
|
531
|
-
/**
|
|
532
|
-
* Set the route pattern
|
|
533
|
-
*/
|
|
534
|
-
setPattern(pattern: string): this;
|
|
535
|
-
/**
|
|
536
|
-
* Returns the stack of middleware registered on the route.
|
|
537
|
-
* The value is shared by reference.
|
|
538
|
-
*/
|
|
539
|
-
getMiddleware(): StoreRouteMiddleware[][];
|
|
540
|
-
/**
|
|
541
|
-
* Returns JSON representation of the route
|
|
542
|
-
*/
|
|
543
|
-
toJSON(): RouteJSON;
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
/**
|
|
547
|
-
* Brisk routes exposes the API to configure the route handler by chaining
|
|
548
|
-
* one of the pre-defined methods.
|
|
549
|
-
*
|
|
550
|
-
* For example: Instead of defining the redirect logic as a callback, one can
|
|
551
|
-
* chain the `.redirect` method.
|
|
552
|
-
*
|
|
553
|
-
* Brisk routes are always registered under the `GET` HTTP method.
|
|
554
|
-
*/
|
|
555
|
-
declare class BriskRoute extends Macroable {
|
|
556
|
-
#private;
|
|
557
|
-
/**
|
|
558
|
-
* Reference to route instance. Set after `setHandler` is called
|
|
559
|
-
*/
|
|
560
|
-
route: null | Route;
|
|
561
|
-
constructor(app: Application<any>, routerMiddleware: ParsedGlobalMiddleware[], options: {
|
|
562
|
-
pattern: string;
|
|
563
|
-
globalMatchers: RouteMatchers$1;
|
|
564
|
-
});
|
|
565
|
-
/**
|
|
566
|
-
* Set handler for the brisk route
|
|
567
|
-
*/
|
|
568
|
-
setHandler(handler: RouteFn): Route;
|
|
569
|
-
/**
|
|
570
|
-
* Redirects to a given route. Params from the original request will
|
|
571
|
-
* be used when no custom params are defined.
|
|
572
|
-
*/
|
|
573
|
-
redirect(identifier: string, params?: any[] | Record<string, any>, options?: MakeUrlOptions & {
|
|
574
|
-
status: number;
|
|
575
|
-
}): Route;
|
|
576
|
-
/**
|
|
577
|
-
* Redirect request to a fixed URL
|
|
578
|
-
*/
|
|
579
|
-
redirectToPath(url: string, options?: {
|
|
580
|
-
status: number;
|
|
581
|
-
}): Route;
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
/**
|
|
585
|
-
* Route resource exposes the API to register multiple routes for a resource.
|
|
586
|
-
*/
|
|
587
|
-
declare class RouteResource extends Macroable {
|
|
588
|
-
#private;
|
|
589
|
-
/**
|
|
590
|
-
* A collection of routes instances that belongs to this resource
|
|
591
|
-
*/
|
|
592
|
-
routes: Route[];
|
|
593
|
-
constructor(app: Application<any>, routerMiddleware: ParsedGlobalMiddleware[], options: {
|
|
594
|
-
resource: string;
|
|
595
|
-
controller: string | LazyImport<Constructor<any>> | Constructor<any>;
|
|
596
|
-
globalMatchers: RouteMatchers$1;
|
|
597
|
-
shallow: boolean;
|
|
598
|
-
});
|
|
599
|
-
/**
|
|
600
|
-
* Register only given routes and remove others
|
|
601
|
-
*/
|
|
602
|
-
only(names: ResourceActionNames[]): this;
|
|
603
|
-
/**
|
|
604
|
-
* Register all routes, except the one's defined
|
|
605
|
-
*/
|
|
606
|
-
except(names: ResourceActionNames[]): this;
|
|
607
|
-
/**
|
|
608
|
-
* Register api only routes. The `create` and `edit` routes, which
|
|
609
|
-
* are meant to show forms will not be registered
|
|
610
|
-
*/
|
|
611
|
-
apiOnly(): this;
|
|
612
|
-
/**
|
|
613
|
-
* Define matcher for params inside the resource
|
|
614
|
-
*/
|
|
615
|
-
where(key: string, matcher: RouteMatcher | string | RegExp): this;
|
|
616
|
-
/**
|
|
617
|
-
* Tap into multiple routes to configure them by their name
|
|
618
|
-
*/
|
|
619
|
-
tap(callback: (route: Route) => void): this;
|
|
620
|
-
tap(actions: ResourceActionNames | ResourceActionNames[], callback: (route: Route) => void): this;
|
|
621
|
-
/**
|
|
622
|
-
* Set the param name for a given resource
|
|
623
|
-
*/
|
|
624
|
-
params(resources: {
|
|
625
|
-
[resource: string]: string;
|
|
626
|
-
}): this;
|
|
627
|
-
/**
|
|
628
|
-
* Prepend name to all the routes
|
|
629
|
-
*/
|
|
630
|
-
as(name: string, normalizeName?: boolean): this;
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
/**
|
|
634
|
-
* Group class exposes the API to take action on a group of routes.
|
|
635
|
-
* The group routes must be pre-defined using the constructor.
|
|
636
|
-
*/
|
|
637
|
-
declare class RouteGroup extends Macroable {
|
|
638
|
-
#private;
|
|
639
|
-
routes: (Route | RouteGroup | RouteResource | BriskRoute)[];
|
|
640
|
-
constructor(routes: (Route | RouteGroup | RouteResource | BriskRoute)[]);
|
|
641
|
-
/**
|
|
642
|
-
* Define route param matcher
|
|
643
|
-
*
|
|
644
|
-
* ```ts
|
|
645
|
-
* Route.group(() => {
|
|
646
|
-
* }).where('id', /^[0-9]+/)
|
|
647
|
-
* ```
|
|
648
|
-
*/
|
|
649
|
-
where(param: string, matcher: RouteMatcher | string | RegExp): this;
|
|
650
|
-
/**
|
|
651
|
-
* Define prefix all the routes in the group.
|
|
652
|
-
*
|
|
653
|
-
* ```ts
|
|
654
|
-
* Route.group(() => {
|
|
655
|
-
* }).prefix('v1')
|
|
656
|
-
* ```
|
|
657
|
-
*/
|
|
658
|
-
prefix(prefix: string): this;
|
|
659
|
-
/**
|
|
660
|
-
* Define domain for all the routes.
|
|
661
|
-
*
|
|
662
|
-
* ```ts
|
|
663
|
-
* Route.group(() => {
|
|
664
|
-
* }).domain(':name.adonisjs.com')
|
|
665
|
-
* ```
|
|
666
|
-
*/
|
|
667
|
-
domain(domain: string): this;
|
|
668
|
-
/**
|
|
669
|
-
* Prepend name to the routes name.
|
|
670
|
-
*
|
|
671
|
-
* ```ts
|
|
672
|
-
* Route.group(() => {
|
|
673
|
-
* }).as('version1')
|
|
674
|
-
* ```
|
|
675
|
-
*/
|
|
676
|
-
as(name: string): this;
|
|
677
|
-
/**
|
|
678
|
-
* Prepend an array of middleware to all routes middleware.
|
|
679
|
-
*
|
|
680
|
-
* ```ts
|
|
681
|
-
* Route.group(() => {
|
|
682
|
-
* }).use(middleware.auth())
|
|
683
|
-
* ```
|
|
684
|
-
*/
|
|
685
|
-
use(middleware: OneOrMore<MiddlewareFn | ParsedNamedMiddleware>): this;
|
|
686
|
-
/**
|
|
687
|
-
* @alias use
|
|
688
|
-
*/
|
|
689
|
-
middleware(middleware: OneOrMore<MiddlewareFn | ParsedNamedMiddleware>): this;
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
/**
|
|
693
|
-
* Route finder is used to find a route by its name, route pattern
|
|
694
|
-
* or the controller.method name.
|
|
695
|
-
*/
|
|
696
|
-
declare class RouteFinder {
|
|
697
|
-
#private;
|
|
698
|
-
constructor(routes: RouteJSON[]);
|
|
699
|
-
/**
|
|
700
|
-
* Find a route by indentifier
|
|
701
|
-
*/
|
|
702
|
-
find(routeIdentifier: string): RouteJSON | null;
|
|
703
|
-
/**
|
|
704
|
-
* Find a route by indentifier or fail
|
|
705
|
-
*/
|
|
706
|
-
findOrFail(routeIdentifier: string): RouteJSON;
|
|
707
|
-
/**
|
|
708
|
-
* Find if a route exists
|
|
709
|
-
*/
|
|
710
|
-
has(routeIdentifier: string): boolean;
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
/**
|
|
714
|
-
* URL builder class is used to create URIs for pre-registered
|
|
715
|
-
* routes.
|
|
716
|
-
*
|
|
717
|
-
* ```ts
|
|
718
|
-
* const builder = new UrlBuilder(encryption, routeFinder)
|
|
719
|
-
*
|
|
720
|
-
* builder
|
|
721
|
-
* .qs({ sort: 'id' })
|
|
722
|
-
* .params([category.id])
|
|
723
|
-
* .make('categories.posts.index')
|
|
724
|
-
* ```
|
|
725
|
-
*/
|
|
726
|
-
declare class UrlBuilder {
|
|
727
|
-
#private;
|
|
728
|
-
constructor(encryption: Encryption, routeFinder: RouteFinder, qsParser: Qs);
|
|
729
|
-
/**
|
|
730
|
-
* Prefix a custom base URL to the final URI
|
|
731
|
-
*/
|
|
732
|
-
prefixUrl(url: string): this;
|
|
733
|
-
/**
|
|
734
|
-
* Disable route lookup. Calling this method considers
|
|
735
|
-
* the "identifier" as the route pattern
|
|
736
|
-
*/
|
|
737
|
-
disableRouteLookup(): this;
|
|
738
|
-
/**
|
|
739
|
-
* Append query string to the final URI
|
|
740
|
-
*/
|
|
741
|
-
qs(queryString?: Record<string, any>): this;
|
|
742
|
-
/**
|
|
743
|
-
* Specify params to apply to the route pattern
|
|
744
|
-
*/
|
|
745
|
-
params(params?: any[] | Record<string, any>): this;
|
|
746
|
-
/**
|
|
747
|
-
* Generate URL for the given route identifier. The identifier can be the
|
|
748
|
-
* route name, controller.method name or the route pattern
|
|
749
|
-
* itself.
|
|
750
|
-
*/
|
|
751
|
-
make(identifier: string): string;
|
|
752
|
-
/**
|
|
753
|
-
* Generate a signed URL for the given route identifier. The identifier can be the
|
|
754
|
-
* route name, controller.method name or the route pattern
|
|
755
|
-
* itself.
|
|
756
|
-
*/
|
|
757
|
-
makeSigned(identifier: string, options?: {
|
|
758
|
-
expiresIn?: string | number;
|
|
759
|
-
purpose?: string;
|
|
760
|
-
}): string;
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
/**
|
|
764
|
-
* Lookup store exposes the API to lookup routes and
|
|
765
|
-
* make URLs for registered routes.
|
|
766
|
-
*/
|
|
767
|
-
declare class LookupStore {
|
|
768
|
-
#private;
|
|
769
|
-
constructor(encryption: Encryption, qsParser: Qs);
|
|
770
|
-
/**
|
|
771
|
-
* Register route JSON payload
|
|
772
|
-
*/
|
|
773
|
-
register(route: RouteJSON): void;
|
|
774
|
-
/**
|
|
775
|
-
* Returns an instance of the URL builder for making
|
|
776
|
-
* route URIs
|
|
777
|
-
*/
|
|
778
|
-
builder(): UrlBuilder;
|
|
779
|
-
/**
|
|
780
|
-
* Returns an instance of the URL builder for a specific
|
|
781
|
-
* domain.
|
|
782
|
-
*/
|
|
783
|
-
builderForDomain(domain: string): UrlBuilder;
|
|
784
|
-
/**
|
|
785
|
-
* Finds a route by its identifier. The identifier can be the
|
|
786
|
-
* route name, controller.method name or the route pattern
|
|
787
|
-
* itself.
|
|
788
|
-
*/
|
|
789
|
-
find(routeIdentifier: string, domain?: string): RouteJSON | null;
|
|
790
|
-
/**
|
|
791
|
-
* Finds a route by its identifier. The identifier can be the
|
|
792
|
-
* route name, controller.method name or the route pattern
|
|
793
|
-
* itself.
|
|
794
|
-
*
|
|
795
|
-
* An error is raised when unable to find the route.
|
|
796
|
-
*/
|
|
797
|
-
findOrFail(routeIdentifier: string, domain?: string): RouteJSON;
|
|
798
|
-
/**
|
|
799
|
-
* Check if a route exists. The identifier can be the
|
|
800
|
-
* route name, controller.method name or the route pattern
|
|
801
|
-
* itself.
|
|
802
|
-
*/
|
|
803
|
-
has(routeIdentifier: string, domain?: string): boolean;
|
|
804
|
-
toJSON(): {
|
|
805
|
-
[domain: string]: RouteJSON[];
|
|
806
|
-
};
|
|
807
|
-
}
|
|
808
|
-
|
|
809
|
-
/**
|
|
810
|
-
* Shortcut methods for commonly used route matchers
|
|
811
|
-
*/
|
|
812
|
-
declare class RouteMatchers extends Macroable {
|
|
813
|
-
/**
|
|
814
|
-
* Enforce value to be a number and also casts it to number data
|
|
815
|
-
* type
|
|
816
|
-
*/
|
|
817
|
-
number(): {
|
|
818
|
-
match: RegExp;
|
|
819
|
-
cast: (value: string) => number;
|
|
820
|
-
};
|
|
821
|
-
/**
|
|
822
|
-
* Enforce value to be formatted as uuid
|
|
823
|
-
*/
|
|
824
|
-
uuid(): {
|
|
825
|
-
match: RegExp;
|
|
826
|
-
cast: (value: string) => string;
|
|
827
|
-
};
|
|
828
|
-
/**
|
|
829
|
-
* Enforce value to be formatted as slug
|
|
830
|
-
*/
|
|
831
|
-
slug(): {
|
|
832
|
-
match: RegExp;
|
|
833
|
-
};
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
/**
|
|
837
|
-
* Router class exposes a unified API to register new routes, group them or
|
|
838
|
-
* create route resources.
|
|
839
|
-
*
|
|
840
|
-
* ```ts
|
|
841
|
-
* const router = new Router()
|
|
842
|
-
*
|
|
843
|
-
* router.get('/', async function () {
|
|
844
|
-
* // handle request
|
|
845
|
-
* })
|
|
846
|
-
* ```
|
|
847
|
-
*/
|
|
848
|
-
declare class Router extends LookupStore {
|
|
849
|
-
#private;
|
|
850
|
-
/**
|
|
851
|
-
* Collection of routes, including route resource and route
|
|
852
|
-
* group. To get a flat list of routes, call `router.toJSON()`
|
|
853
|
-
*/
|
|
854
|
-
routes: (Route | RouteResource | RouteGroup | BriskRoute)[];
|
|
855
|
-
/**
|
|
856
|
-
* A flag to know if routes for explicit domains have been registered.
|
|
857
|
-
* The boolean is computed after calling the "commit" method.
|
|
858
|
-
*/
|
|
859
|
-
usingDomains: boolean;
|
|
860
|
-
/**
|
|
861
|
-
* Shortcut methods for commonly used route matchers
|
|
862
|
-
*/
|
|
863
|
-
matchers: RouteMatchers;
|
|
864
|
-
constructor(app: Application<any>, encryption: Encryption, qsParser: Qs);
|
|
865
|
-
/**
|
|
866
|
-
* Parses the route pattern
|
|
867
|
-
*/
|
|
868
|
-
parsePattern(pattern: string, matchers?: RouteMatchers$1): MatchItRouteToken[];
|
|
869
|
-
/**
|
|
870
|
-
* Define an array of middleware to use on all the routes.
|
|
871
|
-
* Calling this method multiple times pushes to the
|
|
872
|
-
* existing list of middleware
|
|
873
|
-
*/
|
|
874
|
-
use(middleware: LazyImport<MiddlewareAsClass>[]): this;
|
|
875
|
-
/**
|
|
876
|
-
* Define a collection of named middleware. The defined collection is
|
|
877
|
-
* not registered anywhere, but instead converted in a new collection
|
|
878
|
-
* of functions you can apply on the routes, or router groups.
|
|
879
|
-
*/
|
|
880
|
-
named<NamedMiddleware extends Record<string, LazyImport<MiddlewareAsClass>>>(collection: NamedMiddleware): { [K in keyof NamedMiddleware]: <Args extends GetMiddlewareArgs<UnWrapLazyImport<NamedMiddleware[K]>>>(...args: Args) => {
|
|
881
|
-
name: K;
|
|
882
|
-
args: Args[0];
|
|
883
|
-
} & ParsedGlobalMiddleware; };
|
|
884
|
-
/**
|
|
885
|
-
* Add route for a given pattern and methods
|
|
886
|
-
*/
|
|
887
|
-
route<T extends Constructor<any>>(pattern: string, methods: string[], handler: string | RouteFn | [LazyImport<T> | T, GetControllerHandlers<T>?]): Route<T>;
|
|
888
|
-
/**
|
|
889
|
-
* Define a route that handles all common HTTP methods
|
|
890
|
-
*/
|
|
891
|
-
any<T extends Constructor<any>>(pattern: string, handler: string | RouteFn | [LazyImport<T> | T, GetControllerHandlers<T>?]): Route<T>;
|
|
892
|
-
/**
|
|
893
|
-
* Define `GET` route
|
|
894
|
-
*/
|
|
895
|
-
get<T extends Constructor<any>>(pattern: string, handler: string | RouteFn | [LazyImport<T> | T, GetControllerHandlers<T>?]): Route<T>;
|
|
896
|
-
/**
|
|
897
|
-
* Define `POST` route
|
|
898
|
-
*/
|
|
899
|
-
post<T extends Constructor<any>>(pattern: string, handler: string | RouteFn | [LazyImport<T> | T, GetControllerHandlers<T>?]): Route<T>;
|
|
900
|
-
/**
|
|
901
|
-
* Define `PUT` route
|
|
902
|
-
*/
|
|
903
|
-
put<T extends Constructor<any>>(pattern: string, handler: string | RouteFn | [LazyImport<T> | T, GetControllerHandlers<T>?]): Route<T>;
|
|
904
|
-
/**
|
|
905
|
-
* Define `PATCH` route
|
|
906
|
-
*/
|
|
907
|
-
patch<T extends Constructor<any>>(pattern: string, handler: string | RouteFn | [LazyImport<T> | T, GetControllerHandlers<T>?]): Route<T>;
|
|
908
|
-
/**
|
|
909
|
-
* Define `DELETE` route
|
|
910
|
-
*/
|
|
911
|
-
delete<T extends Constructor<any>>(pattern: string, handler: string | RouteFn | [LazyImport<T> | T, GetControllerHandlers<T>?]): Route<T>;
|
|
912
|
-
/**
|
|
913
|
-
* Creates a group of routes. A route group can apply transforms
|
|
914
|
-
* to routes in bulk
|
|
915
|
-
*/
|
|
916
|
-
group(callback: () => void): RouteGroup;
|
|
917
|
-
/**
|
|
918
|
-
* Registers a route resource with conventional set of routes
|
|
919
|
-
*/
|
|
920
|
-
resource(resource: string, controller: string | LazyImport<Constructor<any>> | Constructor<any>): RouteResource;
|
|
921
|
-
/**
|
|
922
|
-
* Register a route resource with shallow nested routes.
|
|
923
|
-
*/
|
|
924
|
-
shallowResource(resource: string, controller: string | LazyImport<Constructor<any>> | Constructor<any>): RouteResource;
|
|
925
|
-
/**
|
|
926
|
-
* Returns a brisk route instance for a given URL pattern
|
|
927
|
-
*/
|
|
928
|
-
on(pattern: string): BriskRoute;
|
|
929
|
-
/**
|
|
930
|
-
* Define matcher for a given param. The global params are applied
|
|
931
|
-
* on all the routes (unless overridden at the route level).
|
|
932
|
-
*/
|
|
933
|
-
where(param: string, matcher: RouteMatcher | string | RegExp): this;
|
|
934
|
-
/**
|
|
935
|
-
* Commit routes to the store. The router is freezed after the
|
|
936
|
-
* commit method is called.
|
|
937
|
-
*/
|
|
938
|
-
commit(): void;
|
|
939
|
-
/**
|
|
940
|
-
* Find route for a given URL, method and optionally domain
|
|
941
|
-
*/
|
|
942
|
-
match(url: string, method: string, hostname?: string | null): null | MatchedRoute;
|
|
943
|
-
/**
|
|
944
|
-
* Make URL to a pre-registered route
|
|
945
|
-
*/
|
|
946
|
-
makeUrl(routeIdentifier: string, params?: any[] | Record<string, any>, options?: MakeUrlOptions): string;
|
|
947
|
-
/**
|
|
948
|
-
* Makes a signed URL to a pre-registered route.
|
|
949
|
-
*/
|
|
950
|
-
makeSignedUrl(routeIdentifier: string, params?: any[] | Record<string, any>, options?: MakeSignedUrlOptions): string;
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
/**
|
|
954
|
-
* Exposes the API to construct redirect routes
|
|
955
|
-
*/
|
|
956
|
-
declare class Redirect {
|
|
957
|
-
#private;
|
|
958
|
-
constructor(request: IncomingMessage, response: Response, router: Router, qs: Qs);
|
|
959
|
-
/**
|
|
960
|
-
* Set a custom status code.
|
|
961
|
-
*/
|
|
962
|
-
status(statusCode: number): this;
|
|
963
|
-
/**
|
|
964
|
-
* Clearing query string values added using the
|
|
965
|
-
* "withQs" method
|
|
966
|
-
*/
|
|
967
|
-
clearQs(): this;
|
|
968
|
-
/**
|
|
969
|
-
* Define query string for the redirect. Not passing
|
|
970
|
-
* any value will forward the current request query
|
|
971
|
-
* string.
|
|
972
|
-
*/
|
|
973
|
-
withQs(): this;
|
|
974
|
-
withQs(values: Record<string, any>): this;
|
|
975
|
-
withQs(name: string, value: any): this;
|
|
976
|
-
/**
|
|
977
|
-
* Redirect to the previous path.
|
|
978
|
-
*/
|
|
979
|
-
back(): void;
|
|
980
|
-
/**
|
|
981
|
-
* Redirect the request using a route identifier.
|
|
982
|
-
*/
|
|
983
|
-
toRoute(routeIdentifier: string, params?: any[] | Record<string, any>, options?: MakeUrlOptions): void;
|
|
984
|
-
/**
|
|
985
|
-
* Redirect the request using a path.
|
|
986
|
-
*/
|
|
987
|
-
toPath(url: string): void;
|
|
988
|
-
}
|
|
989
|
-
|
|
990
|
-
/**
|
|
991
|
-
* The response is a wrapper over [ServerResponse](https://nodejs.org/api/http.html#http_class_http_serverresponse)
|
|
992
|
-
* streamlining the process of writing response body and automatically setting up appropriate headers.
|
|
993
|
-
*/
|
|
994
|
-
declare class Response extends Macroable {
|
|
995
|
-
#private;
|
|
996
|
-
request: IncomingMessage;
|
|
997
|
-
response: ServerResponse;
|
|
998
|
-
/**
|
|
999
|
-
* Does response has body set that will written to the
|
|
1000
|
-
* response socket at the end of the request
|
|
1001
|
-
*/
|
|
1002
|
-
get hasLazyBody(): boolean;
|
|
1003
|
-
/**
|
|
1004
|
-
* Find if the response has non-stream content
|
|
1005
|
-
*/
|
|
1006
|
-
get hasContent(): boolean;
|
|
1007
|
-
/**
|
|
1008
|
-
* Returns true when response body is set using "response.stream"
|
|
1009
|
-
* method
|
|
1010
|
-
*/
|
|
1011
|
-
get hasStream(): boolean;
|
|
1012
|
-
/**
|
|
1013
|
-
* Returns true when response body is set using "response.download"
|
|
1014
|
-
* or "response.attachment" methods
|
|
1015
|
-
*/
|
|
1016
|
-
get hasFileToStream(): boolean;
|
|
1017
|
-
/**
|
|
1018
|
-
* Returns the response content. Check if the response
|
|
1019
|
-
* has content using the "hasContent" method
|
|
1020
|
-
*/
|
|
1021
|
-
get content(): [any, boolean, (string | undefined)?] | undefined;
|
|
1022
|
-
/**
|
|
1023
|
-
* Returns reference to the stream set using "response.stream"
|
|
1024
|
-
* method
|
|
1025
|
-
*/
|
|
1026
|
-
get outgoingStream(): stream.Readable | undefined;
|
|
1027
|
-
/**
|
|
1028
|
-
* Returns reference to the file path set using "response.stream"
|
|
1029
|
-
* method.
|
|
1030
|
-
*/
|
|
1031
|
-
get fileToStream(): {
|
|
1032
|
-
path: string;
|
|
1033
|
-
generateEtag: boolean;
|
|
1034
|
-
} | undefined;
|
|
1035
|
-
/**
|
|
1036
|
-
* Lazy body is used to set the response body. However, do not
|
|
1037
|
-
* write it on the socket immediately unless `response.finish`
|
|
1038
|
-
* is called.
|
|
1039
|
-
*/
|
|
1040
|
-
lazyBody: Partial<{
|
|
1041
|
-
content: [any, boolean, string?];
|
|
1042
|
-
stream: [ResponseStream, ((error: NodeJS.ErrnoException) => [string, number?])?];
|
|
1043
|
-
fileToStream: [string, boolean, ((error: NodeJS.ErrnoException) => [string, number?])?];
|
|
1044
|
-
}>;
|
|
1045
|
-
/**
|
|
1046
|
-
* The ctx will be set by the context itself. It creates a circular
|
|
1047
|
-
* reference
|
|
1048
|
-
*/
|
|
1049
|
-
ctx?: HttpContext;
|
|
1050
|
-
constructor(request: IncomingMessage, response: ServerResponse, encryption: Encryption, config: ResponseConfig, router: Router, qs: Qs);
|
|
1051
|
-
/**
|
|
1052
|
-
* Returns a boolean telling if response is finished or not.
|
|
1053
|
-
* Any more attempts to update headers or body will result
|
|
1054
|
-
* in raised exceptions.
|
|
1055
|
-
*/
|
|
1056
|
-
get finished(): boolean;
|
|
1057
|
-
/**
|
|
1058
|
-
* Returns a boolean telling if response headers has been sent or not.
|
|
1059
|
-
* Any more attempts to update headers will result in raised
|
|
1060
|
-
* exceptions.
|
|
1061
|
-
*/
|
|
1062
|
-
get headersSent(): boolean;
|
|
1063
|
-
/**
|
|
1064
|
-
* Returns a boolean telling if response headers and body is written
|
|
1065
|
-
* or not. When value is `true`, you can feel free to write headers
|
|
1066
|
-
* and body.
|
|
1067
|
-
*/
|
|
1068
|
-
get isPending(): boolean;
|
|
1069
|
-
/**
|
|
1070
|
-
* Writes the body with appropriate response headers. Etag header is set
|
|
1071
|
-
* when `generateEtag` is set to `true`.
|
|
1072
|
-
*
|
|
1073
|
-
* Empty body results in `204`.
|
|
1074
|
-
*/
|
|
1075
|
-
protected writeBody(content: any, generateEtag: boolean, jsonpCallbackName?: string): void;
|
|
1076
|
-
/**
|
|
1077
|
-
* Stream the body to the response and handles cleaning up the stream
|
|
1078
|
-
*/
|
|
1079
|
-
protected streamBody(body: ResponseStream, errorCallback?: (error: NodeJS.ErrnoException) => [string, number?]): Promise<void>;
|
|
1080
|
-
/**
|
|
1081
|
-
* Downloads a file by streaming it to the response
|
|
1082
|
-
*/
|
|
1083
|
-
protected streamFileForDownload(filePath: string, generateEtag: boolean, errorCallback?: (error: NodeJS.ErrnoException) => [string, number?]): Promise<void>;
|
|
1084
|
-
/**
|
|
1085
|
-
* Writes headers with the Node.js res object using the
|
|
1086
|
-
* response.setHeader method
|
|
1087
|
-
*/
|
|
1088
|
-
relayHeaders(): void;
|
|
1089
|
-
/**
|
|
1090
|
-
* Calls res.writeHead on the Node.js res object.
|
|
1091
|
-
*/
|
|
1092
|
-
writeHead(statusCode?: number): this;
|
|
1093
|
-
/**
|
|
1094
|
-
* Returns the existing value for a given HTTP response
|
|
1095
|
-
* header.
|
|
1096
|
-
*/
|
|
1097
|
-
getHeader(key: string): http.OutgoingHttpHeader | undefined;
|
|
1098
|
-
/**
|
|
1099
|
-
* Get response headers
|
|
1100
|
-
*/
|
|
1101
|
-
getHeaders(): {
|
|
1102
|
-
[x: string]: http.OutgoingHttpHeader | undefined;
|
|
1103
|
-
accept?: string | string[] | undefined;
|
|
1104
|
-
"accept-charset"?: string | string[] | undefined;
|
|
1105
|
-
"accept-encoding"?: string | string[] | undefined;
|
|
1106
|
-
"accept-language"?: string | string[] | undefined;
|
|
1107
|
-
"accept-ranges"?: string | undefined;
|
|
1108
|
-
"access-control-allow-credentials"?: string | undefined;
|
|
1109
|
-
"access-control-allow-headers"?: string | undefined;
|
|
1110
|
-
"access-control-allow-methods"?: string | undefined;
|
|
1111
|
-
"access-control-allow-origin"?: string | undefined;
|
|
1112
|
-
"access-control-expose-headers"?: string | undefined;
|
|
1113
|
-
"access-control-max-age"?: string | undefined;
|
|
1114
|
-
"access-control-request-headers"?: string | undefined;
|
|
1115
|
-
"access-control-request-method"?: string | undefined;
|
|
1116
|
-
age?: string | undefined;
|
|
1117
|
-
allow?: string | undefined;
|
|
1118
|
-
authorization?: string | undefined;
|
|
1119
|
-
"cache-control"?: string | undefined;
|
|
1120
|
-
"cdn-cache-control"?: string | undefined;
|
|
1121
|
-
connection?: string | string[] | undefined;
|
|
1122
|
-
"content-disposition"?: string | undefined;
|
|
1123
|
-
"content-encoding"?: string | undefined;
|
|
1124
|
-
"content-language"?: string | undefined;
|
|
1125
|
-
"content-length"?: string | number | undefined;
|
|
1126
|
-
"content-location"?: string | undefined;
|
|
1127
|
-
"content-range"?: string | undefined;
|
|
1128
|
-
"content-security-policy"?: string | undefined;
|
|
1129
|
-
"content-security-policy-report-only"?: string | undefined;
|
|
1130
|
-
cookie?: string | string[] | undefined;
|
|
1131
|
-
dav?: string | string[] | undefined;
|
|
1132
|
-
dnt?: string | undefined;
|
|
1133
|
-
date?: string | undefined;
|
|
1134
|
-
etag?: string | undefined;
|
|
1135
|
-
expect?: string | undefined;
|
|
1136
|
-
expires?: string | undefined;
|
|
1137
|
-
forwarded?: string | undefined;
|
|
1138
|
-
from?: string | undefined;
|
|
1139
|
-
host?: string | undefined;
|
|
1140
|
-
"if-match"?: string | undefined;
|
|
1141
|
-
"if-modified-since"?: string | undefined;
|
|
1142
|
-
"if-none-match"?: string | undefined;
|
|
1143
|
-
"if-range"?: string | undefined;
|
|
1144
|
-
"if-unmodified-since"?: string | undefined;
|
|
1145
|
-
"last-modified"?: string | undefined;
|
|
1146
|
-
link?: string | string[] | undefined;
|
|
1147
|
-
location?: string | undefined;
|
|
1148
|
-
"max-forwards"?: string | undefined;
|
|
1149
|
-
origin?: string | undefined;
|
|
1150
|
-
prgama?: string | string[] | undefined;
|
|
1151
|
-
"proxy-authenticate"?: string | string[] | undefined;
|
|
1152
|
-
"proxy-authorization"?: string | undefined;
|
|
1153
|
-
"public-key-pins"?: string | undefined;
|
|
1154
|
-
"public-key-pins-report-only"?: string | undefined;
|
|
1155
|
-
range?: string | undefined;
|
|
1156
|
-
referer?: string | undefined;
|
|
1157
|
-
"referrer-policy"?: string | undefined;
|
|
1158
|
-
refresh?: string | undefined;
|
|
1159
|
-
"retry-after"?: string | undefined;
|
|
1160
|
-
"sec-websocket-accept"?: string | undefined;
|
|
1161
|
-
"sec-websocket-extensions"?: string | string[] | undefined;
|
|
1162
|
-
"sec-websocket-key"?: string | undefined;
|
|
1163
|
-
"sec-websocket-protocol"?: string | string[] | undefined;
|
|
1164
|
-
"sec-websocket-version"?: string | undefined;
|
|
1165
|
-
server?: string | undefined;
|
|
1166
|
-
"set-cookie"?: string | string[] | undefined;
|
|
1167
|
-
"strict-transport-security"?: string | undefined;
|
|
1168
|
-
te?: string | undefined;
|
|
1169
|
-
trailer?: string | undefined;
|
|
1170
|
-
"transfer-encoding"?: string | undefined;
|
|
1171
|
-
"user-agent"?: string | undefined;
|
|
1172
|
-
upgrade?: string | undefined;
|
|
1173
|
-
"upgrade-insecure-requests"?: string | undefined;
|
|
1174
|
-
vary?: string | undefined;
|
|
1175
|
-
via?: string | string[] | undefined;
|
|
1176
|
-
warning?: string | undefined;
|
|
1177
|
-
"www-authenticate"?: string | string[] | undefined;
|
|
1178
|
-
"x-content-type-options"?: string | undefined;
|
|
1179
|
-
"x-dns-prefetch-control"?: string | undefined;
|
|
1180
|
-
"x-frame-options"?: string | undefined;
|
|
1181
|
-
"x-xss-protection"?: string | undefined;
|
|
1182
|
-
};
|
|
1183
|
-
/**
|
|
1184
|
-
* Set header on the response. To `append` values to the existing header, we suggest
|
|
1185
|
-
* using [[append]] method.
|
|
1186
|
-
*
|
|
1187
|
-
* If `value` is non existy, then header won't be set.
|
|
1188
|
-
*
|
|
1189
|
-
* @example
|
|
1190
|
-
* ```js
|
|
1191
|
-
* response.header('content-type', 'application/json')
|
|
1192
|
-
* ```
|
|
1193
|
-
*/
|
|
1194
|
-
header(key: string, value: CastableHeader): this;
|
|
1195
|
-
/**
|
|
1196
|
-
* Append value to an existing header. To replace the value, we suggest using
|
|
1197
|
-
* [[header]] method.
|
|
1198
|
-
*
|
|
1199
|
-
* If `value` is not existy, then header won't be set.
|
|
1200
|
-
*
|
|
1201
|
-
* @example
|
|
1202
|
-
* ```js
|
|
1203
|
-
* response.append('set-cookie', 'username=virk')
|
|
1204
|
-
* ```
|
|
1205
|
-
*/
|
|
1206
|
-
append(key: string, value: CastableHeader): this;
|
|
1207
|
-
/**
|
|
1208
|
-
* Adds HTTP response header, when it doesn't exists already.
|
|
1209
|
-
*/
|
|
1210
|
-
safeHeader(key: string, value: CastableHeader): this;
|
|
1211
|
-
/**
|
|
1212
|
-
* Removes the existing response header from being sent.
|
|
1213
|
-
*/
|
|
1214
|
-
removeHeader(key: string): this;
|
|
1215
|
-
/**
|
|
1216
|
-
* Returns the status code for the response
|
|
1217
|
-
*/
|
|
1218
|
-
getStatus(): number;
|
|
1219
|
-
/**
|
|
1220
|
-
* Set HTTP status code
|
|
1221
|
-
*/
|
|
1222
|
-
status(code: number): this;
|
|
1223
|
-
/**
|
|
1224
|
-
* Set's status code only when it's not explictly
|
|
1225
|
-
* set
|
|
1226
|
-
*/
|
|
1227
|
-
safeStatus(code: number): this;
|
|
1228
|
-
/**
|
|
1229
|
-
* Set response type by looking up for the mime-type using
|
|
1230
|
-
* partial types like file extensions.
|
|
1231
|
-
*
|
|
1232
|
-
* Make sure to read [mime-types](https://www.npmjs.com/package/mime-types) docs
|
|
1233
|
-
* too.
|
|
1234
|
-
*
|
|
1235
|
-
* @example
|
|
1236
|
-
* ```js
|
|
1237
|
-
* response.type('.json') // Content-type: application/json
|
|
1238
|
-
* ```
|
|
1239
|
-
*/
|
|
1240
|
-
type(type: string, charset?: string): this;
|
|
1241
|
-
/**
|
|
1242
|
-
* Set the Vary HTTP header
|
|
1243
|
-
*/
|
|
1244
|
-
vary(field: string | string[]): this;
|
|
1245
|
-
/**
|
|
1246
|
-
* Set etag by computing hash from the body. This class will set the etag automatically
|
|
1247
|
-
* when `etag = true` in the defined config object.
|
|
1248
|
-
*
|
|
1249
|
-
* Use this function, when you want to compute etag manually for some other resons.
|
|
1250
|
-
*/
|
|
1251
|
-
setEtag(body: any, weak?: boolean): this;
|
|
1252
|
-
/**
|
|
1253
|
-
* Returns a boolean telling if the new response etag evaluates same
|
|
1254
|
-
* as the request header `if-none-match`. In case of `true`, the
|
|
1255
|
-
* server must return `304` response, telling the browser to
|
|
1256
|
-
* use the client cache.
|
|
1257
|
-
*
|
|
1258
|
-
* You won't have to deal with this method directly, since AdonisJs will
|
|
1259
|
-
* handle this for you when `http.etag = true` inside `config/app.js` file.
|
|
1260
|
-
*
|
|
1261
|
-
* However, this is how you can use it manually.
|
|
1262
|
-
*
|
|
1263
|
-
* @example
|
|
1264
|
-
* ```js
|
|
1265
|
-
* const responseBody = view.render('some-view')
|
|
1266
|
-
*
|
|
1267
|
-
* // sets the HTTP etag header for response
|
|
1268
|
-
* response.setEtag(responseBody)
|
|
1269
|
-
*
|
|
1270
|
-
* if (response.fresh()) {
|
|
1271
|
-
* response.sendStatus(304)
|
|
1272
|
-
* } else {
|
|
1273
|
-
* response.send(responseBody)
|
|
1274
|
-
* }
|
|
1275
|
-
* ```
|
|
1276
|
-
*/
|
|
1277
|
-
fresh(): boolean;
|
|
1278
|
-
/**
|
|
1279
|
-
* Returns the response body. Returns null when response
|
|
1280
|
-
* body is a stream
|
|
1281
|
-
*/
|
|
1282
|
-
getBody(): any;
|
|
1283
|
-
/**
|
|
1284
|
-
* Send the body as response and optionally generate etag. The default value
|
|
1285
|
-
* is read from `config/app.js` file, using `http.etag` property.
|
|
1286
|
-
*
|
|
1287
|
-
* This method buffers the body if `explicitEnd = true`, which is the default
|
|
1288
|
-
* behavior and do not change, unless you know what you are doing.
|
|
1289
|
-
*/
|
|
1290
|
-
send(body: any, generateEtag?: boolean): void;
|
|
1291
|
-
/**
|
|
1292
|
-
* Alias of [[send]]
|
|
1293
|
-
*/
|
|
1294
|
-
json(body: any, generateEtag?: boolean): void;
|
|
1295
|
-
/**
|
|
1296
|
-
* Writes response as JSONP. The callback name is resolved as follows, with priority
|
|
1297
|
-
* from top to bottom.
|
|
1298
|
-
*
|
|
1299
|
-
* 1. Explicitly defined as 2nd Param.
|
|
1300
|
-
* 2. Fetch from request query string.
|
|
1301
|
-
* 3. Use the config value `http.jsonpCallbackName` from `config/app.js`.
|
|
1302
|
-
* 4. Fallback to `callback`.
|
|
1303
|
-
*
|
|
1304
|
-
* This method buffers the body if `explicitEnd = true`, which is the default
|
|
1305
|
-
* behavior and do not change, unless you know what you are doing.
|
|
1306
|
-
*/
|
|
1307
|
-
jsonp(body: any, callbackName?: string, generateEtag?: boolean): void;
|
|
1308
|
-
/**
|
|
1309
|
-
* Pipe stream to the response. This method will gracefully destroy
|
|
1310
|
-
* the stream, avoiding memory leaks.
|
|
1311
|
-
*
|
|
1312
|
-
* If `raiseErrors=false`, then this method will self handle all the exceptions by
|
|
1313
|
-
* writing a generic HTTP response. To have more control over the error, it is
|
|
1314
|
-
* recommended to set `raiseErrors=true` and wrap this function inside a
|
|
1315
|
-
* `try/catch` statement.
|
|
1316
|
-
*
|
|
1317
|
-
* Streaming a file from the disk and showing 404 when file is missing.
|
|
1318
|
-
*
|
|
1319
|
-
* @example
|
|
1320
|
-
* ```js
|
|
1321
|
-
* // Errors handled automatically with generic HTTP response
|
|
1322
|
-
* response.stream(fs.createReadStream('file.txt'))
|
|
1323
|
-
*
|
|
1324
|
-
* // Manually handle (note the await call)
|
|
1325
|
-
* try {
|
|
1326
|
-
* await response.stream(fs.createReadStream('file.txt'))
|
|
1327
|
-
* } catch () {
|
|
1328
|
-
* response.status(404).send('File not found')
|
|
1329
|
-
* }
|
|
1330
|
-
* ```
|
|
1331
|
-
*/
|
|
1332
|
-
stream(body: ResponseStream, errorCallback?: (error: NodeJS.ErrnoException) => [string, number?]): void;
|
|
1333
|
-
/**
|
|
1334
|
-
* Download file by streaming it from the file path. This method will setup
|
|
1335
|
-
* appropriate `Content-type`, `Content-type` and `Last-modified` headers.
|
|
1336
|
-
*
|
|
1337
|
-
* Unexpected stream errors are handled gracefully to avoid memory leaks.
|
|
1338
|
-
*
|
|
1339
|
-
* If `raiseErrors=false`, then this method will self handle all the exceptions by
|
|
1340
|
-
* writing a generic HTTP response. To have more control over the error, it is
|
|
1341
|
-
* recommended to set `raiseErrors=true` and wrap this function inside a
|
|
1342
|
-
* `try/catch` statement.
|
|
1343
|
-
*
|
|
1344
|
-
* @example
|
|
1345
|
-
* ```js
|
|
1346
|
-
* // Errors handled automatically with generic HTTP response
|
|
1347
|
-
* response.download('somefile.jpg')
|
|
1348
|
-
*
|
|
1349
|
-
* // Manually handle (note the await call)
|
|
1350
|
-
* try {
|
|
1351
|
-
* await response.download('somefile.jpg')
|
|
1352
|
-
* } catch (error) {
|
|
1353
|
-
* response.status(error.code === 'ENOENT' ? 404 : 500)
|
|
1354
|
-
* response.send('Cannot process file')
|
|
1355
|
-
* }
|
|
1356
|
-
* ```
|
|
1357
|
-
*/
|
|
1358
|
-
download(filePath: string, generateEtag?: boolean, errorCallback?: (error: NodeJS.ErrnoException) => [string, number?]): void;
|
|
1359
|
-
/**
|
|
1360
|
-
* Download the file by forcing the user to save the file vs displaying it
|
|
1361
|
-
* within the browser.
|
|
1362
|
-
*
|
|
1363
|
-
* Internally calls [[download]]
|
|
1364
|
-
*/
|
|
1365
|
-
attachment(filePath: string, name?: string, disposition?: string, generateEtag?: boolean, errorCallback?: (error: NodeJS.ErrnoException) => [string, number?]): void;
|
|
1366
|
-
/**
|
|
1367
|
-
* Set the location header.
|
|
1368
|
-
*
|
|
1369
|
-
* @example
|
|
1370
|
-
* ```js
|
|
1371
|
-
* response.location('/login')
|
|
1372
|
-
* ```
|
|
1373
|
-
*/
|
|
1374
|
-
location(url: string): this;
|
|
1375
|
-
/**
|
|
1376
|
-
* Redirect the request.
|
|
1377
|
-
*
|
|
1378
|
-
* @example
|
|
1379
|
-
* ```js
|
|
1380
|
-
* response.redirect('/foo')
|
|
1381
|
-
* response.redirect().toRoute('foo.bar')
|
|
1382
|
-
* response.redirect().back()
|
|
1383
|
-
* ```
|
|
1384
|
-
*/
|
|
1385
|
-
redirect(): Redirect;
|
|
1386
|
-
redirect(path: string, forwardQueryString?: boolean, statusCode?: number): void;
|
|
1387
|
-
/**
|
|
1388
|
-
* Abort the request with custom body and a status code. 400 is
|
|
1389
|
-
* used when status is not defined
|
|
1390
|
-
*/
|
|
1391
|
-
abort(body: any, status?: number): never;
|
|
1392
|
-
/**
|
|
1393
|
-
* Abort the request with custom body and a status code when
|
|
1394
|
-
* passed condition returns `true`
|
|
1395
|
-
*/
|
|
1396
|
-
abortIf(condition: unknown, body: any, status?: number): asserts condition is undefined | null | false;
|
|
1397
|
-
/**
|
|
1398
|
-
* Abort the request with custom body and a status code when
|
|
1399
|
-
* passed condition returns `false`
|
|
1400
|
-
*/
|
|
1401
|
-
abortUnless<T>(condition: T, body: any, status?: number): asserts condition is Exclude<T, undefined | null | false>;
|
|
1402
|
-
/**
|
|
1403
|
-
* Set signed cookie as the response header. The inline options overrides
|
|
1404
|
-
* all options from the config.
|
|
1405
|
-
*/
|
|
1406
|
-
cookie(key: string, value: any, options?: Partial<CookieOptions>): this;
|
|
1407
|
-
/**
|
|
1408
|
-
* Set encrypted cookie as the response header. The inline options overrides
|
|
1409
|
-
* all options from the config.
|
|
1410
|
-
*/
|
|
1411
|
-
encryptedCookie(key: string, value: any, options?: Partial<CookieOptions>): this;
|
|
1412
|
-
/**
|
|
1413
|
-
* Set unsigned cookie as the response header. The inline options overrides
|
|
1414
|
-
* all options from the config.
|
|
1415
|
-
*/
|
|
1416
|
-
plainCookie(key: string, value: any, options?: Partial<CookieOptions & {
|
|
1417
|
-
encode: boolean;
|
|
1418
|
-
}>): this;
|
|
1419
|
-
/**
|
|
1420
|
-
* Clear existing cookie.
|
|
1421
|
-
*/
|
|
1422
|
-
clearCookie(key: string, options?: Partial<CookieOptions>): this;
|
|
1423
|
-
/**
|
|
1424
|
-
* Finishes the response by writing the lazy body, when `explicitEnd = true`
|
|
1425
|
-
* and response is already pending.
|
|
1426
|
-
*
|
|
1427
|
-
* Calling this method twice or when `explicitEnd = false` is noop.
|
|
1428
|
-
*/
|
|
1429
|
-
finish(): void;
|
|
1430
|
-
/**
|
|
1431
|
-
* Shorthand method to finish request with "100" status code
|
|
1432
|
-
*/
|
|
1433
|
-
continue(): void;
|
|
1434
|
-
/**
|
|
1435
|
-
* Shorthand method to finish request with "101" status code
|
|
1436
|
-
*/
|
|
1437
|
-
switchingProtocols(): void;
|
|
1438
|
-
/**
|
|
1439
|
-
* Shorthand method to finish request with "200" status code
|
|
1440
|
-
*/
|
|
1441
|
-
ok(body: any, generateEtag?: boolean): void;
|
|
1442
|
-
/**
|
|
1443
|
-
* Shorthand method to finish request with "201" status code
|
|
1444
|
-
*/
|
|
1445
|
-
created(body?: any, generateEtag?: boolean): void;
|
|
1446
|
-
/**
|
|
1447
|
-
* Shorthand method to finish request with "202" status code
|
|
1448
|
-
*/
|
|
1449
|
-
accepted(body: any, generateEtag?: boolean): void;
|
|
1450
|
-
/**
|
|
1451
|
-
* Shorthand method to finish request with "203" status code
|
|
1452
|
-
*/
|
|
1453
|
-
nonAuthoritativeInformation(body: any, generateEtag?: boolean): void;
|
|
1454
|
-
/**
|
|
1455
|
-
* Shorthand method to finish request with "204" status code
|
|
1456
|
-
*/
|
|
1457
|
-
noContent(): void;
|
|
1458
|
-
/**
|
|
1459
|
-
* Shorthand method to finish request with "205" status code
|
|
1460
|
-
*/
|
|
1461
|
-
resetContent(): void;
|
|
1462
|
-
/**
|
|
1463
|
-
* Shorthand method to finish request with "206" status code
|
|
1464
|
-
*/
|
|
1465
|
-
partialContent(body: any, generateEtag?: boolean): void;
|
|
1466
|
-
/**
|
|
1467
|
-
* Shorthand method to finish request with "300" status code
|
|
1468
|
-
*/
|
|
1469
|
-
multipleChoices(body?: any, generateEtag?: boolean): void;
|
|
1470
|
-
/**
|
|
1471
|
-
* Shorthand method to finish request with "301" status code
|
|
1472
|
-
*/
|
|
1473
|
-
movedPermanently(body?: any, generateEtag?: boolean): void;
|
|
1474
|
-
/**
|
|
1475
|
-
* Shorthand method to finish request with "302" status code
|
|
1476
|
-
*/
|
|
1477
|
-
movedTemporarily(body?: any, generateEtag?: boolean): void;
|
|
1478
|
-
/**
|
|
1479
|
-
* Shorthand method to finish request with "303" status code
|
|
1480
|
-
*/
|
|
1481
|
-
seeOther(body?: any, generateEtag?: boolean): void;
|
|
1482
|
-
/**
|
|
1483
|
-
* Shorthand method to finish request with "304" status code
|
|
1484
|
-
*/
|
|
1485
|
-
notModified(body?: any, generateEtag?: boolean): void;
|
|
1486
|
-
/**
|
|
1487
|
-
* Shorthand method to finish request with "305" status code
|
|
1488
|
-
*/
|
|
1489
|
-
useProxy(body?: any, generateEtag?: boolean): void;
|
|
1490
|
-
/**
|
|
1491
|
-
* Shorthand method to finish request with "307" status code
|
|
1492
|
-
*/
|
|
1493
|
-
temporaryRedirect(body?: any, generateEtag?: boolean): void;
|
|
1494
|
-
/**
|
|
1495
|
-
* Shorthand method to finish request with "400" status code
|
|
1496
|
-
*/
|
|
1497
|
-
badRequest(body?: any, generateEtag?: boolean): void;
|
|
1498
|
-
/**
|
|
1499
|
-
* Shorthand method to finish request with "401" status code
|
|
1500
|
-
*/
|
|
1501
|
-
unauthorized(body?: any, generateEtag?: boolean): void;
|
|
1502
|
-
/**
|
|
1503
|
-
* Shorthand method to finish request with "402" status code
|
|
1504
|
-
*/
|
|
1505
|
-
paymentRequired(body?: any, generateEtag?: boolean): void;
|
|
1506
|
-
/**
|
|
1507
|
-
* Shorthand method to finish request with "403" status code
|
|
1508
|
-
*/
|
|
1509
|
-
forbidden(body?: any, generateEtag?: boolean): void;
|
|
1510
|
-
/**
|
|
1511
|
-
* Shorthand method to finish request with "404" status code
|
|
1512
|
-
*/
|
|
1513
|
-
notFound(body?: any, generateEtag?: boolean): void;
|
|
1514
|
-
/**
|
|
1515
|
-
* Shorthand method to finish request with "405" status code
|
|
1516
|
-
*/
|
|
1517
|
-
methodNotAllowed(body?: any, generateEtag?: boolean): void;
|
|
1518
|
-
/**
|
|
1519
|
-
* Shorthand method to finish request with "406" status code
|
|
1520
|
-
*/
|
|
1521
|
-
notAcceptable(body?: any, generateEtag?: boolean): void;
|
|
1522
|
-
/**
|
|
1523
|
-
* Shorthand method to finish request with "407" status code
|
|
1524
|
-
*/
|
|
1525
|
-
proxyAuthenticationRequired(body?: any, generateEtag?: boolean): void;
|
|
1526
|
-
/**
|
|
1527
|
-
* Shorthand method to finish request with "408" status code
|
|
1528
|
-
*/
|
|
1529
|
-
requestTimeout(body?: any, generateEtag?: boolean): void;
|
|
1530
|
-
/**
|
|
1531
|
-
* Shorthand method to finish request with "409" status code
|
|
1532
|
-
*/
|
|
1533
|
-
conflict(body?: any, generateEtag?: boolean): void;
|
|
1534
|
-
/**
|
|
1535
|
-
* Shorthand method to finish request with "401" status code
|
|
1536
|
-
*/
|
|
1537
|
-
gone(body?: any, generateEtag?: boolean): void;
|
|
1538
|
-
/**
|
|
1539
|
-
* Shorthand method to finish request with "411" status code
|
|
1540
|
-
*/
|
|
1541
|
-
lengthRequired(body?: any, generateEtag?: boolean): void;
|
|
1542
|
-
/**
|
|
1543
|
-
* Shorthand method to finish request with "412" status code
|
|
1544
|
-
*/
|
|
1545
|
-
preconditionFailed(body?: any, generateEtag?: boolean): void;
|
|
1546
|
-
/**
|
|
1547
|
-
* Shorthand method to finish request with "413" status code
|
|
1548
|
-
*/
|
|
1549
|
-
requestEntityTooLarge(body?: any, generateEtag?: boolean): void;
|
|
1550
|
-
/**
|
|
1551
|
-
* Shorthand method to finish request with "414" status code
|
|
1552
|
-
*/
|
|
1553
|
-
requestUriTooLong(body?: any, generateEtag?: boolean): void;
|
|
1554
|
-
/**
|
|
1555
|
-
* Shorthand method to finish request with "415" status code
|
|
1556
|
-
*/
|
|
1557
|
-
unsupportedMediaType(body?: any, generateEtag?: boolean): void;
|
|
1558
|
-
/**
|
|
1559
|
-
* Shorthand method to finish request with "416" status code
|
|
1560
|
-
*/
|
|
1561
|
-
requestedRangeNotSatisfiable(body?: any, generateEtag?: boolean): void;
|
|
1562
|
-
/**
|
|
1563
|
-
* Shorthand method to finish request with "417" status code
|
|
1564
|
-
*/
|
|
1565
|
-
expectationFailed(body?: any, generateEtag?: boolean): void;
|
|
1566
|
-
/**
|
|
1567
|
-
* Shorthand method to finish request with "422" status code
|
|
1568
|
-
*/
|
|
1569
|
-
unprocessableEntity(body?: any, generateEtag?: boolean): void;
|
|
1570
|
-
/**
|
|
1571
|
-
* Shorthand method to finish request with "429" status code
|
|
1572
|
-
*/
|
|
1573
|
-
tooManyRequests(body?: any, generateEtag?: boolean): void;
|
|
1574
|
-
/**
|
|
1575
|
-
* Shorthand method to finish request with "500" status code
|
|
1576
|
-
*/
|
|
1577
|
-
internalServerError(body?: any, generateEtag?: boolean): void;
|
|
1578
|
-
/**
|
|
1579
|
-
* Shorthand method to finish request with "501" status code
|
|
1580
|
-
*/
|
|
1581
|
-
notImplemented(body?: any, generateEtag?: boolean): void;
|
|
1582
|
-
/**
|
|
1583
|
-
* Shorthand method to finish request with "502" status code
|
|
1584
|
-
*/
|
|
1585
|
-
badGateway(body?: any, generateEtag?: boolean): void;
|
|
1586
|
-
/**
|
|
1587
|
-
* Shorthand method to finish request with "503" status code
|
|
1588
|
-
*/
|
|
1589
|
-
serviceUnavailable(body?: any, generateEtag?: boolean): void;
|
|
1590
|
-
/**
|
|
1591
|
-
* Shorthand method to finish request with "504" status code
|
|
1592
|
-
*/
|
|
1593
|
-
gatewayTimeout(body?: any, generateEtag?: boolean): void;
|
|
1594
|
-
/**
|
|
1595
|
-
* Shorthand method to finish request with "505" status code
|
|
1596
|
-
*/
|
|
1597
|
-
httpVersionNotSupported(body?: any, generateEtag?: boolean): void;
|
|
1598
|
-
}
|
|
1599
|
-
|
|
1600
|
-
/**
|
|
1601
|
-
* Http context encapsulates properties for a given HTTP request. The
|
|
1602
|
-
* context class can be extended using macros and getters.
|
|
1603
|
-
*/
|
|
1604
|
-
declare class HttpContext extends Macroable {
|
|
1605
|
-
request: Request;
|
|
1606
|
-
response: Response;
|
|
1607
|
-
logger: Logger;
|
|
1608
|
-
containerResolver: ContainerResolver<any>;
|
|
1609
|
-
/**
|
|
1610
|
-
* Find if async localstorage is enabled for HTTP requests
|
|
1611
|
-
* or not
|
|
1612
|
-
*/
|
|
1613
|
-
static get usingAsyncLocalStorage(): boolean;
|
|
1614
|
-
/**
|
|
1615
|
-
* Get access to the HTTP context. Available only when
|
|
1616
|
-
* "usingAsyncLocalStorage" is true
|
|
1617
|
-
*/
|
|
1618
|
-
static get(): HttpContext | null;
|
|
1619
|
-
/**
|
|
1620
|
-
* Get the HttpContext instance or raise an exception if not
|
|
1621
|
-
* available
|
|
1622
|
-
*/
|
|
1623
|
-
static getOrFail(): HttpContext;
|
|
1624
|
-
/**
|
|
1625
|
-
* Run a method that doesn't have access to HTTP context from
|
|
1626
|
-
* the async local storage.
|
|
1627
|
-
*/
|
|
1628
|
-
static runOutsideContext<T>(callback: (...args: any[]) => T, ...args: any[]): T;
|
|
1629
|
-
/**
|
|
1630
|
-
* Reference to the current route. Not available inside
|
|
1631
|
-
* server middleware
|
|
1632
|
-
*/
|
|
1633
|
-
route?: StoreRouteNode;
|
|
1634
|
-
/**
|
|
1635
|
-
* A unique key for the current route
|
|
1636
|
-
*/
|
|
1637
|
-
routeKey?: string;
|
|
1638
|
-
/**
|
|
1639
|
-
* Route params
|
|
1640
|
-
*/
|
|
1641
|
-
params: Record<string, any>;
|
|
1642
|
-
/**
|
|
1643
|
-
* Route subdomains
|
|
1644
|
-
*/
|
|
1645
|
-
subdomains: Record<string, any>;
|
|
1646
|
-
constructor(request: Request, response: Response, logger: Logger, containerResolver: ContainerResolver<any>);
|
|
1647
|
-
/**
|
|
1648
|
-
* A helper to see top level properties on the context object
|
|
1649
|
-
*/
|
|
1650
|
-
inspect(): string;
|
|
1651
|
-
}
|
|
1652
|
-
|
|
1653
|
-
/**
|
|
1654
|
-
* HTTP Request class exposes the interface to consistently read values
|
|
1655
|
-
* related to a given HTTP request. The class is wrapper over
|
|
1656
|
-
* [IncomingMessage](https://nodejs.org/api/http.html#http_class_http_incomingmessage)
|
|
1657
|
-
* and has extended API.
|
|
1658
|
-
*
|
|
1659
|
-
* You can access the original [IncomingMessage](https://nodejs.org/api/http.html#http_class_http_incomingmessage)
|
|
1660
|
-
* using `request.request` property.
|
|
1661
|
-
*/
|
|
1662
|
-
declare class Request extends Macroable {
|
|
1663
|
-
#private;
|
|
1664
|
-
request: IncomingMessage;
|
|
1665
|
-
response: ServerResponse;
|
|
1666
|
-
/**
|
|
1667
|
-
* Parses copy of the URL with query string as a string and not
|
|
1668
|
-
* object. This is done to build URL's with query string without
|
|
1669
|
-
* stringifying the object
|
|
1670
|
-
*/
|
|
1671
|
-
parsedUrl: UrlWithStringQuery;
|
|
1672
|
-
/**
|
|
1673
|
-
* The ctx will be set by the context itself. It creates a circular
|
|
1674
|
-
* reference
|
|
1675
|
-
*/
|
|
1676
|
-
ctx?: HttpContext;
|
|
1677
|
-
constructor(request: IncomingMessage, response: ServerResponse, encryption: Encryption, config: RequestConfig, qsParser: Qs);
|
|
1678
|
-
/**
|
|
1679
|
-
* Returns the request id from the `x-request-id` header. The
|
|
1680
|
-
* header is untouched, if it already exists.
|
|
1681
|
-
*/
|
|
1682
|
-
id(): string | undefined;
|
|
1683
|
-
/**
|
|
1684
|
-
* Set initial request body. A copy of the input will be maintained as the original
|
|
1685
|
-
* request body. Since the request body and query string is subject to mutations, we
|
|
1686
|
-
* keep one original reference to flash old data (whenever required).
|
|
1687
|
-
*
|
|
1688
|
-
* This method is supposed to be invoked by the body parser and must be called only
|
|
1689
|
-
* once. For further mutations make use of `updateBody` method.
|
|
1690
|
-
*/
|
|
1691
|
-
setInitialBody(body: Record<string, any>): void;
|
|
1692
|
-
/**
|
|
1693
|
-
* Update the request body with new data object. The `all` property
|
|
1694
|
-
* will be re-computed by merging the query string and request
|
|
1695
|
-
* body.
|
|
1696
|
-
*/
|
|
1697
|
-
updateBody(body: Record<string, any>): void;
|
|
1698
|
-
/**
|
|
1699
|
-
* Update the request raw body. Bodyparser sets this when unable to parse
|
|
1700
|
-
* the request body or when request is multipart/form-data.
|
|
1701
|
-
*/
|
|
1702
|
-
updateRawBody(rawBody: string): void;
|
|
1703
|
-
/**
|
|
1704
|
-
* Update the query string with the new data object. The `all` property
|
|
1705
|
-
* will be re-computed by merging the query and the request body.
|
|
1706
|
-
*/
|
|
1707
|
-
updateQs(data: Record<string, any>): void;
|
|
1708
|
-
/**
|
|
1709
|
-
* Returns route params
|
|
1710
|
-
*/
|
|
1711
|
-
params(): Record<string, any>;
|
|
1712
|
-
/**
|
|
1713
|
-
* Returns the query string object by reference
|
|
1714
|
-
*/
|
|
1715
|
-
qs(): Record<string, any>;
|
|
1716
|
-
/**
|
|
1717
|
-
* Returns reference to the request body
|
|
1718
|
-
*/
|
|
1719
|
-
body(): Record<string, any>;
|
|
1720
|
-
/**
|
|
1721
|
-
* Returns reference to the merged copy of request body
|
|
1722
|
-
* and query string
|
|
1723
|
-
*/
|
|
1724
|
-
all(): Record<string, any>;
|
|
1725
|
-
/**
|
|
1726
|
-
* Returns reference to the merged copy of original request
|
|
1727
|
-
* query string and body
|
|
1728
|
-
*/
|
|
1729
|
-
original(): Record<string, any>;
|
|
1730
|
-
/**
|
|
1731
|
-
* Returns the request raw body (if exists), or returns `null`.
|
|
1732
|
-
*
|
|
1733
|
-
* Ideally you must be dealing with the parsed body accessed using [[input]], [[all]] or
|
|
1734
|
-
* [[post]] methods. The `raw` body is always a string.
|
|
1735
|
-
*/
|
|
1736
|
-
raw(): string | null;
|
|
1737
|
-
/**
|
|
1738
|
-
* Returns value for a given key from the request body or query string.
|
|
1739
|
-
* The `defaultValue` is used when original value is `undefined`.
|
|
1740
|
-
*
|
|
1741
|
-
* @example
|
|
1742
|
-
* ```js
|
|
1743
|
-
* request.input('username')
|
|
1744
|
-
*
|
|
1745
|
-
* // with default value
|
|
1746
|
-
* request.input('username', 'virk')
|
|
1747
|
-
* ```
|
|
1748
|
-
*/
|
|
1749
|
-
input(key: string, defaultValue?: any): any;
|
|
1750
|
-
/**
|
|
1751
|
-
* Returns value for a given key from route params
|
|
1752
|
-
*
|
|
1753
|
-
* @example
|
|
1754
|
-
* ```js
|
|
1755
|
-
* request.param('id')
|
|
1756
|
-
*
|
|
1757
|
-
* // with default value
|
|
1758
|
-
* request.param('id', 1)
|
|
1759
|
-
* ```
|
|
1760
|
-
*/
|
|
1761
|
-
param(key: string, defaultValue?: any): any;
|
|
1762
|
-
/**
|
|
1763
|
-
* Get everything from the request body except the given keys.
|
|
1764
|
-
*
|
|
1765
|
-
* @example
|
|
1766
|
-
* ```js
|
|
1767
|
-
* request.except(['_csrf'])
|
|
1768
|
-
* ```
|
|
1769
|
-
*/
|
|
1770
|
-
except(keys: string[]): Record<string, any>;
|
|
1771
|
-
/**
|
|
1772
|
-
* Get value for specified keys.
|
|
1773
|
-
*
|
|
1774
|
-
* @example
|
|
1775
|
-
* ```js
|
|
1776
|
-
* request.only(['username', 'age'])
|
|
1777
|
-
* ```
|
|
1778
|
-
*/
|
|
1779
|
-
only<T extends string>(keys: T[]): {
|
|
1780
|
-
[K in T]: any;
|
|
1781
|
-
};
|
|
1782
|
-
/**
|
|
1783
|
-
* Returns the HTTP request method. This is the original
|
|
1784
|
-
* request method. For spoofed request method, make
|
|
1785
|
-
* use of [[method]].
|
|
1786
|
-
*
|
|
1787
|
-
* @example
|
|
1788
|
-
* ```js
|
|
1789
|
-
* request.intended()
|
|
1790
|
-
* ```
|
|
1791
|
-
*/
|
|
1792
|
-
intended(): string;
|
|
1793
|
-
/**
|
|
1794
|
-
* Returns the request HTTP method by taking method spoofing into account.
|
|
1795
|
-
*
|
|
1796
|
-
* Method spoofing works when all of the following are true.
|
|
1797
|
-
*
|
|
1798
|
-
* 1. `app.http.allowMethodSpoofing` config value is true.
|
|
1799
|
-
* 2. request query string has `_method`.
|
|
1800
|
-
* 3. The [[intended]] request method is `POST`.
|
|
1801
|
-
*
|
|
1802
|
-
* @example
|
|
1803
|
-
* ```js
|
|
1804
|
-
* request.method()
|
|
1805
|
-
* ```
|
|
1806
|
-
*/
|
|
1807
|
-
method(): string;
|
|
1808
|
-
/**
|
|
1809
|
-
* Returns a copy of headers as an object
|
|
1810
|
-
*/
|
|
1811
|
-
headers(): IncomingHttpHeaders;
|
|
1812
|
-
/**
|
|
1813
|
-
* Returns value for a given header key. The default value is
|
|
1814
|
-
* used when original value is `undefined`.
|
|
1815
|
-
*/
|
|
1816
|
-
header(key: string, defaultValue?: any): string | undefined;
|
|
1817
|
-
/**
|
|
1818
|
-
* Returns the ip address of the user. This method is optimize to fetch
|
|
1819
|
-
* ip address even when running your AdonisJs app behind a proxy.
|
|
1820
|
-
*
|
|
1821
|
-
* You can also define your own custom function to compute the ip address by
|
|
1822
|
-
* defining `app.http.getIp` as a function inside the config file.
|
|
1823
|
-
*
|
|
1824
|
-
* ```js
|
|
1825
|
-
* {
|
|
1826
|
-
* http: {
|
|
1827
|
-
* getIp (request) {
|
|
1828
|
-
* // I am using nginx as a proxy server and want to trust 'x-real-ip'
|
|
1829
|
-
* return request.header('x-real-ip')
|
|
1830
|
-
* }
|
|
1831
|
-
* }
|
|
1832
|
-
* }
|
|
1833
|
-
* ```
|
|
1834
|
-
*
|
|
1835
|
-
* You can control the behavior of trusting the proxy values by defining it
|
|
1836
|
-
* inside the `config/app.js` file.
|
|
1837
|
-
*
|
|
1838
|
-
* ```js
|
|
1839
|
-
* {
|
|
1840
|
-
* http: {
|
|
1841
|
-
* trustProxy: '127.0.0.1'
|
|
1842
|
-
* }
|
|
1843
|
-
* }
|
|
1844
|
-
* ```
|
|
1845
|
-
*
|
|
1846
|
-
* The value of trustProxy is passed directly to [proxy-addr](https://www.npmjs.com/package/proxy-addr)
|
|
1847
|
-
*/
|
|
1848
|
-
ip(): string;
|
|
1849
|
-
/**
|
|
1850
|
-
* Returns an array of ip addresses from most to least trusted one.
|
|
1851
|
-
* This method is optimize to fetch ip address even when running
|
|
1852
|
-
* your AdonisJs app behind a proxy.
|
|
1853
|
-
*
|
|
1854
|
-
* You can control the behavior of trusting the proxy values by defining it
|
|
1855
|
-
* inside the `config/app.js` file.
|
|
1856
|
-
*
|
|
1857
|
-
* ```js
|
|
1858
|
-
* {
|
|
1859
|
-
* http: {
|
|
1860
|
-
* trustProxy: '127.0.0.1'
|
|
1861
|
-
* }
|
|
1862
|
-
* }
|
|
1863
|
-
* ```
|
|
1864
|
-
*
|
|
1865
|
-
* The value of trustProxy is passed directly to [proxy-addr](https://www.npmjs.com/package/proxy-addr)
|
|
1866
|
-
*/
|
|
1867
|
-
ips(): string[];
|
|
1868
|
-
/**
|
|
1869
|
-
* Returns the request protocol by checking for the URL protocol or
|
|
1870
|
-
* `X-Forwarded-Proto` header.
|
|
1871
|
-
*
|
|
1872
|
-
* If the `trust` is evaluated to `false`, then URL protocol is returned,
|
|
1873
|
-
* otherwise `X-Forwarded-Proto` header is used (if exists).
|
|
1874
|
-
*
|
|
1875
|
-
* You can control the behavior of trusting the proxy values by defining it
|
|
1876
|
-
* inside the `config/app.js` file.
|
|
1877
|
-
*
|
|
1878
|
-
* ```js
|
|
1879
|
-
* {
|
|
1880
|
-
* http: {
|
|
1881
|
-
* trustProxy: '127.0.0.1'
|
|
1882
|
-
* }
|
|
1883
|
-
* }
|
|
1884
|
-
* ```
|
|
1885
|
-
*
|
|
1886
|
-
* The value of trustProxy is passed directly to [proxy-addr](https://www.npmjs.com/package/proxy-addr)
|
|
1887
|
-
*/
|
|
1888
|
-
protocol(): string;
|
|
1889
|
-
/**
|
|
1890
|
-
* Returns a boolean telling if request is served over `https`
|
|
1891
|
-
* or not. Check [[protocol]] method to know how protocol is
|
|
1892
|
-
* fetched.
|
|
1893
|
-
*/
|
|
1894
|
-
secure(): boolean;
|
|
1895
|
-
/**
|
|
1896
|
-
* Returns the request host. If proxy headers are trusted, then
|
|
1897
|
-
* `X-Forwarded-Host` is given priority over the `Host` header.
|
|
1898
|
-
*
|
|
1899
|
-
* You can control the behavior of trusting the proxy values by defining it
|
|
1900
|
-
* inside the `config/app.js` file.
|
|
1901
|
-
*
|
|
1902
|
-
* ```js
|
|
1903
|
-
* {
|
|
1904
|
-
* http: {
|
|
1905
|
-
* trustProxy: '127.0.0.1'
|
|
1906
|
-
* }
|
|
1907
|
-
* }
|
|
1908
|
-
* ```
|
|
1909
|
-
*
|
|
1910
|
-
* The value of trustProxy is passed directly to [proxy-addr](https://www.npmjs.com/package/proxy-addr)
|
|
1911
|
-
*/
|
|
1912
|
-
host(): string | null;
|
|
1913
|
-
/**
|
|
1914
|
-
* Returns the request hostname. If proxy headers are trusted, then
|
|
1915
|
-
* `X-Forwarded-Host` is given priority over the `Host` header.
|
|
1916
|
-
*
|
|
1917
|
-
* You can control the behavior of trusting the proxy values by defining it
|
|
1918
|
-
* inside the `config/app.js` file.
|
|
1919
|
-
*
|
|
1920
|
-
* ```js
|
|
1921
|
-
* {
|
|
1922
|
-
* http: {
|
|
1923
|
-
* trustProxy: '127.0.0.1'
|
|
1924
|
-
* }
|
|
1925
|
-
* }
|
|
1926
|
-
* ```
|
|
1927
|
-
*
|
|
1928
|
-
* The value of trustProxy is passed directly to [proxy-addr](https://www.npmjs.com/package/proxy-addr)
|
|
1929
|
-
*/
|
|
1930
|
-
hostname(): string | null;
|
|
1931
|
-
/**
|
|
1932
|
-
* Returns an array of subdomains for the given host. An empty array is
|
|
1933
|
-
* returned if [[hostname]] is `null` or is an IP address.
|
|
1934
|
-
*
|
|
1935
|
-
* Also `www` is not considered as a subdomain
|
|
1936
|
-
*/
|
|
1937
|
-
subdomains(): string[];
|
|
1938
|
-
/**
|
|
1939
|
-
* Returns a boolean telling, if request `X-Requested-With === 'xmlhttprequest'`
|
|
1940
|
-
* or not.
|
|
1941
|
-
*/
|
|
1942
|
-
ajax(): boolean;
|
|
1943
|
-
/**
|
|
1944
|
-
* Returns a boolean telling, if request has `X-Pjax` header
|
|
1945
|
-
* set or not
|
|
1946
|
-
*/
|
|
1947
|
-
pjax(): boolean;
|
|
1948
|
-
/**
|
|
1949
|
-
* Returns the request relative URL.
|
|
1950
|
-
*
|
|
1951
|
-
* @example
|
|
1952
|
-
* ```js
|
|
1953
|
-
* request.url()
|
|
1954
|
-
*
|
|
1955
|
-
* // include query string
|
|
1956
|
-
* request.url(true)
|
|
1957
|
-
* ```
|
|
1958
|
-
*/
|
|
1959
|
-
url(includeQueryString?: boolean): string;
|
|
1960
|
-
/**
|
|
1961
|
-
* Returns the complete HTTP url by combining
|
|
1962
|
-
* [[protocol]]://[[hostname]]/[[url]]
|
|
1963
|
-
*
|
|
1964
|
-
* @example
|
|
1965
|
-
* ```js
|
|
1966
|
-
* request.completeUrl()
|
|
1967
|
-
*
|
|
1968
|
-
* // include query string
|
|
1969
|
-
* request.completeUrl(true)
|
|
1970
|
-
* ```
|
|
1971
|
-
*/
|
|
1972
|
-
completeUrl(includeQueryString?: boolean): string;
|
|
1973
|
-
/**
|
|
1974
|
-
* Find if the current HTTP request is for the given route or the routes
|
|
1975
|
-
*/
|
|
1976
|
-
matchesRoute(routeIdentifier: string | string[]): boolean;
|
|
1977
|
-
/**
|
|
1978
|
-
* Returns the best matching content type of the request by
|
|
1979
|
-
* matching against the given types.
|
|
1980
|
-
*
|
|
1981
|
-
* The content type is picked from the `content-type` header and request
|
|
1982
|
-
* must have body.
|
|
1983
|
-
*
|
|
1984
|
-
* The method response highly depends upon the types array values. Described below:
|
|
1985
|
-
*
|
|
1986
|
-
* | Type(s) | Return value |
|
|
1987
|
-
* |----------|---------------|
|
|
1988
|
-
* | ['json'] | json |
|
|
1989
|
-
* | ['application/*'] | application/json |
|
|
1990
|
-
* | ['vnd+json'] | application/json |
|
|
1991
|
-
*
|
|
1992
|
-
* @example
|
|
1993
|
-
* ```js
|
|
1994
|
-
* const bodyType = request.is(['json', 'xml'])
|
|
1995
|
-
*
|
|
1996
|
-
* if (bodyType === 'json') {
|
|
1997
|
-
* // process JSON
|
|
1998
|
-
* }
|
|
1999
|
-
*
|
|
2000
|
-
* if (bodyType === 'xml') {
|
|
2001
|
-
* // process XML
|
|
2002
|
-
* }
|
|
2003
|
-
* ```
|
|
2004
|
-
*/
|
|
2005
|
-
is(types: string[]): string | null;
|
|
2006
|
-
/**
|
|
2007
|
-
* Returns the best type using `Accept` header and
|
|
2008
|
-
* by matching it against the given types.
|
|
2009
|
-
*
|
|
2010
|
-
* If nothing is matched, then `null` will be returned
|
|
2011
|
-
*
|
|
2012
|
-
* Make sure to check [accepts](https://www.npmjs.com/package/accepts) package
|
|
2013
|
-
* docs too.
|
|
2014
|
-
*
|
|
2015
|
-
* @example
|
|
2016
|
-
* ```js
|
|
2017
|
-
* switch (request.accepts(['json', 'html'])) {
|
|
2018
|
-
* case 'json':
|
|
2019
|
-
* return response.json(user)
|
|
2020
|
-
* case 'html':
|
|
2021
|
-
* return view.render('user', { user })
|
|
2022
|
-
* default:
|
|
2023
|
-
* // decide yourself
|
|
2024
|
-
* }
|
|
2025
|
-
* ```
|
|
2026
|
-
*/
|
|
2027
|
-
accepts<T extends string>(types: T[]): T | null;
|
|
2028
|
-
/**
|
|
2029
|
-
* Return the types that the request accepts, in the order of the
|
|
2030
|
-
* client's preference (most preferred first).
|
|
2031
|
-
*
|
|
2032
|
-
* Make sure to check [accepts](https://www.npmjs.com/package/accepts) package
|
|
2033
|
-
* docs too.
|
|
2034
|
-
*/
|
|
2035
|
-
types(): string[];
|
|
2036
|
-
/**
|
|
2037
|
-
* Returns the best language using `Accept-language` header
|
|
2038
|
-
* and by matching it against the given languages.
|
|
2039
|
-
*
|
|
2040
|
-
* If nothing is matched, then `null` will be returned
|
|
2041
|
-
*
|
|
2042
|
-
* Make sure to check [accepts](https://www.npmjs.com/package/accepts) package
|
|
2043
|
-
* docs too.
|
|
2044
|
-
*
|
|
2045
|
-
* @example
|
|
2046
|
-
* ```js
|
|
2047
|
-
* switch (request.language(['fr', 'de'])) {
|
|
2048
|
-
* case 'fr':
|
|
2049
|
-
* return view.render('about', { lang: 'fr' })
|
|
2050
|
-
* case 'de':
|
|
2051
|
-
* return view.render('about', { lang: 'de' })
|
|
2052
|
-
* default:
|
|
2053
|
-
* return view.render('about', { lang: 'en' })
|
|
2054
|
-
* }
|
|
2055
|
-
* ```
|
|
2056
|
-
*/
|
|
2057
|
-
language<T extends string>(languages: T[]): T | null;
|
|
2058
|
-
/**
|
|
2059
|
-
* Return the languages that the request accepts, in the order of the
|
|
2060
|
-
* client's preference (most preferred first).
|
|
2061
|
-
*
|
|
2062
|
-
* Make sure to check [accepts](https://www.npmjs.com/package/accepts) package
|
|
2063
|
-
* docs too.
|
|
2064
|
-
*/
|
|
2065
|
-
languages(): string[];
|
|
2066
|
-
/**
|
|
2067
|
-
* Returns the best charset using `Accept-charset` header
|
|
2068
|
-
* and by matching it against the given charsets.
|
|
2069
|
-
*
|
|
2070
|
-
* If nothing is matched, then `null` will be returned
|
|
2071
|
-
*
|
|
2072
|
-
* Make sure to check [accepts](https://www.npmjs.com/package/accepts) package
|
|
2073
|
-
* docs too.
|
|
2074
|
-
*
|
|
2075
|
-
* @example
|
|
2076
|
-
* ```js
|
|
2077
|
-
* switch (request.charset(['utf-8', 'ISO-8859-1'])) {
|
|
2078
|
-
* case 'utf-8':
|
|
2079
|
-
* // make utf-8 friendly response
|
|
2080
|
-
* case 'ISO-8859-1':
|
|
2081
|
-
* // make ISO-8859-1 friendly response
|
|
2082
|
-
* }
|
|
2083
|
-
* ```
|
|
2084
|
-
*/
|
|
2085
|
-
charset<T extends string>(charsets: T[]): T | null;
|
|
2086
|
-
/**
|
|
2087
|
-
* Return the charsets that the request accepts, in the order of the
|
|
2088
|
-
* client's preference (most preferred first).
|
|
2089
|
-
*
|
|
2090
|
-
* Make sure to check [accepts](https://www.npmjs.com/package/accepts) package
|
|
2091
|
-
* docs too.
|
|
2092
|
-
*/
|
|
2093
|
-
charsets(): string[];
|
|
2094
|
-
/**
|
|
2095
|
-
* Returns the best encoding using `Accept-encoding` header
|
|
2096
|
-
* and by matching it against the given encodings.
|
|
2097
|
-
*
|
|
2098
|
-
* If nothing is matched, then `null` will be returned
|
|
2099
|
-
*
|
|
2100
|
-
* Make sure to check [accepts](https://www.npmjs.com/package/accepts) package
|
|
2101
|
-
* docs too.
|
|
2102
|
-
*/
|
|
2103
|
-
encoding<T extends string>(encodings: T[]): T | null;
|
|
2104
|
-
/**
|
|
2105
|
-
* Return the charsets that the request accepts, in the order of the
|
|
2106
|
-
* client's preference (most preferred first).
|
|
2107
|
-
*
|
|
2108
|
-
* Make sure to check [accepts](https://www.npmjs.com/package/accepts) package
|
|
2109
|
-
* docs too.
|
|
2110
|
-
*/
|
|
2111
|
-
encodings(): string[];
|
|
2112
|
-
/**
|
|
2113
|
-
* Returns a boolean telling if request has body
|
|
2114
|
-
*/
|
|
2115
|
-
hasBody(): boolean;
|
|
2116
|
-
/**
|
|
2117
|
-
* Returns a boolean telling if the new response etag evaluates same
|
|
2118
|
-
* as the request header `if-none-match`. In case of `true`, the
|
|
2119
|
-
* server must return `304` response, telling the browser to
|
|
2120
|
-
* use the client cache.
|
|
2121
|
-
*
|
|
2122
|
-
* You won't have to deal with this method directly, since AdonisJs will
|
|
2123
|
-
* handle this for you when `http.etag = true` inside `config/app.js` file.
|
|
2124
|
-
*
|
|
2125
|
-
* However, this is how you can use it manually.
|
|
2126
|
-
*
|
|
2127
|
-
* ```js
|
|
2128
|
-
* const responseBody = view.render('some-view')
|
|
2129
|
-
*
|
|
2130
|
-
* // sets the HTTP etag header for response
|
|
2131
|
-
* response.setEtag(responseBody)
|
|
2132
|
-
*
|
|
2133
|
-
* if (request.fresh()) {
|
|
2134
|
-
* response.sendStatus(304)
|
|
2135
|
-
* } else {
|
|
2136
|
-
* response.send(responseBody)
|
|
2137
|
-
* }
|
|
2138
|
-
* ```
|
|
2139
|
-
*/
|
|
2140
|
-
fresh(): boolean;
|
|
2141
|
-
/**
|
|
2142
|
-
* Opposite of [[fresh]]
|
|
2143
|
-
*/
|
|
2144
|
-
stale(): boolean;
|
|
2145
|
-
/**
|
|
2146
|
-
* Returns all parsed and signed cookies. Signed cookies ensures
|
|
2147
|
-
* that their value isn't tampered.
|
|
2148
|
-
*/
|
|
2149
|
-
cookiesList(): Record<string, any>;
|
|
2150
|
-
/**
|
|
2151
|
-
* Returns value for a given key from signed cookies. Optional
|
|
2152
|
-
* defaultValue is returned when actual value is undefined.
|
|
2153
|
-
*/
|
|
2154
|
-
cookie(key: string, defaultValue?: string): any;
|
|
2155
|
-
/**
|
|
2156
|
-
* Returns value for a given key from signed cookies. Optional
|
|
2157
|
-
* defaultValue is returned when actual value is undefined.
|
|
2158
|
-
*/
|
|
2159
|
-
encryptedCookie(key: string, defaultValue?: string): any;
|
|
2160
|
-
/**
|
|
2161
|
-
* Returns value for a given key from unsigned cookies. Optional
|
|
2162
|
-
* defaultValue is returned when actual value is undefined.
|
|
2163
|
-
*/
|
|
2164
|
-
plainCookie(key: string, options?: {
|
|
2165
|
-
defaultValue?: string;
|
|
2166
|
-
encoded?: boolean;
|
|
2167
|
-
}): any;
|
|
2168
|
-
plainCookie(key: string, defaultValue?: string, encoded?: boolean): any;
|
|
2169
|
-
/**
|
|
2170
|
-
* Returns a boolean telling if a signed url as a valid signature
|
|
2171
|
-
* or not.
|
|
2172
|
-
*/
|
|
2173
|
-
hasValidSignature(purpose?: string): boolean;
|
|
2174
|
-
/**
|
|
2175
|
-
* Serializes request to JSON format
|
|
2176
|
-
*/
|
|
2177
|
-
serialize(): {
|
|
2178
|
-
id: string | undefined;
|
|
2179
|
-
url: string;
|
|
2180
|
-
query: string | null;
|
|
2181
|
-
body: Record<string, any>;
|
|
2182
|
-
params: Record<string, any>;
|
|
2183
|
-
headers: IncomingHttpHeaders;
|
|
2184
|
-
method: string;
|
|
2185
|
-
protocol: string;
|
|
2186
|
-
cookies: Record<string, any>;
|
|
2187
|
-
hostname: string | null;
|
|
2188
|
-
ip: string;
|
|
2189
|
-
subdomains: Record<string, any>;
|
|
2190
|
-
};
|
|
2191
|
-
/**
|
|
2192
|
-
* toJSON copy of the request
|
|
2193
|
-
*/
|
|
2194
|
-
toJSON(): {
|
|
2195
|
-
id: string | undefined;
|
|
2196
|
-
url: string;
|
|
2197
|
-
query: string | null;
|
|
2198
|
-
body: Record<string, any>;
|
|
2199
|
-
params: Record<string, any>;
|
|
2200
|
-
headers: IncomingHttpHeaders;
|
|
2201
|
-
method: string;
|
|
2202
|
-
protocol: string;
|
|
2203
|
-
cookies: Record<string, any>;
|
|
2204
|
-
hostname: string | null;
|
|
2205
|
-
ip: string;
|
|
2206
|
-
subdomains: Record<string, any>;
|
|
2207
|
-
};
|
|
2208
|
-
}
|
|
2209
|
-
|
|
2210
|
-
export { MatchedRoute as A, BriskRoute as B, Constructor as C, RouteMatcher as D, ErrorHandlerAsAClass as E, RouteMatchers$1 as F, GetMiddlewareArgs as G, HttpContext as H, RouteJSON as I, ResourceActionNames as J, MakeUrlOptions as K, LazyImport as L, MiddlewareAsClass as M, MakeSignedUrlOptions as N, OneOrMore as O, ParsedGlobalMiddleware as P, QSParserConfig as Q, Router as R, ServerConfig as S, TestingMiddlewarePipeline as T, UnWrapLazyImport as U, HttpRequestFinishedPayload as V, ServerErrorHandler as W, Request as a, Response as b, StatusPageRange as c, StatusPageRenderer as d, HttpError as e, Redirect as f, Route as g, RouteGroup as h, RouteResource as i, Qs as j, RequestConfig as k, ResponseConfig as l, MiddlewareFn as m, ParsedNamedMiddleware as n, CookieOptions as o, CastableHeader as p, ResponseStream as q, GetControllerHandlers as r, MatchItRouteToken as s, RouteFn as t, StoreRouteHandler as u, StoreRouteMiddleware as v, StoreRouteNode as w, StoreMethodNode as x, StoreDomainNode as y, StoreRoutesTree as z };
|