Repository navigation
Expand file tree
/
Copy pathindex.d.ts
More file actions
1356 lines (1328 loc) · 49.2 KB
/
Copy pathindex.d.ts
File metadata and controls
1356 lines (1328 loc) · 49.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* auto-generated by NAPI-RS */
/* eslint-disable */
export declare class Bytes {
constructor()
static fromOwner(owner: Buffer): Bytes
get length(): number
isEmpty(): boolean
isUnique(): boolean
static copyFromSlice(data: Uint8Array): Bytes
slice(startIdx: number, endIdx: number): Bytes
sliceRef(subset: Uint8Array): Bytes
splitOff(mid: number): Bytes
splitTo(at: number): Bytes
truncate(len: number): void
clear(): void
}
/**
* Create a new cookie parser middleware function using the given secret and
* options.
*
* - `secret` a string or array used for signing cookies. This is optional and
* if not specified, will not parse signed cookies. If a string is provided,
* this is used as the secret. If an array is provided, an attempt will be
* made to unsign the cookie with each secret in order.
*
* - `options` an object that is passed to cookie.parse as the second option. See cookie for more information.
* decode a function to decode the value of the cookie
* The middleware will parse the Cookie header on the request and expose the cookie data as the property req.cookies and, if a secret was provided, as the property req.signedCookies. These properties are name value pairs of the cookie name to cookie value.
*/
export declare class CookieParserMiddleware {
constructor(secret?: string | Array<string> | undefined | null, options?: JsCookieParserOptions | undefined | null)
run(request: Request, response: Response): Promise<boolean>
}
export declare class FileStat {
isDirectory(): boolean
isFile(): boolean
isSymbolicLink(): boolean
get size(): number
get atimeMs(): bigint
get mtimeMs(): bigint
get birthtimeMs(): bigint
}
/**
* This is a built-in middleware function in Express. It parses incoming
* requests with JSON payloads.
*
* Returns middleware that only parses JSON and only looks at requests where
* the `Content-Type` header matches the `type` option. This parser accepts
* any Unicode encoding of the body and supports automatic inflation of `gzip`
* and `deflate` encodings.
*
* A new `body` object containing the parsed data is populated on the
* `request` object after the middleware (i.e. `req.body`), or `undefined` if
* there was no body to parse, the `Content-Type` was not matched, or an error
* occurred.
*
* > As `req.body`’s shape is based on user-controlled input, all properties
* > and values in this object are untrusted and should be validated before
* > trusting. For example, `req.body.foo.toString()` may fail in multiple
* > ways, for example `foo` may not be there or may not be a string, and
* > `toString` may not be a function and instead a string or other
* > user-input.
*/
export declare class JsonMiddleware {
constructor(options?: JsJsonOptions | undefined | null)
run(request: Request, response: Response): Promise<boolean>
}
/**
* This is a built-in middleware function in Express. It parses incoming
* requests with JSON payloads.
*
* Returns middleware that only parses JSON and only looks at requests where
* the `Content-Type` header matches the `type` option. This parser accepts
* any Unicode encoding of the body and supports automatic inflation of `gzip`
* and `deflate` encodings.
*
* A new `body` object containing the parsed data is populated on the
* `request` object after the middleware (i.e. `req.body`), or `undefined` if
* there was no body to parse, the `Content-Type` was not matched, or an error
* occurred.
*
* > As `req.body`’s shape is based on user-controlled input, all properties
* > and values in this object are untrusted and should be validated before
* > trusting. For example, `req.body.foo.toString()` may fail in multiple
* > ways, for example `foo` may not be there or may not be a string, and
* > `toString` may not be a function and instead a string or other
* > user-input.
*/
export declare class RawMiddleware {
constructor(options?: JsRawOptions | undefined | null)
run(request: Request, response: Response): Promise<boolean>
}
export declare class Request {
/**
* Checks if the specified content types are acceptable, based on the
* request’s Accept HTTP header field. The method returns the best match, or
* if none of the specified content types is acceptable, returns false (in
* which case, the application should respond with 406 "Not Acceptable").
*
* The type value may be a single MIME type string (such as
* "application/json"), an extension name such as "json", a comma-delimited
* list, or an array. For a list or array, the method returns the best match
* (if any).
*
* ```javascript
* // Accept: text/html
* req.accepts('html')
* // => "html"
*
* // Accept: text/*, application/json
* req.accepts('html')u
* // => "html"
* req.accepts('text/html')
* // => "text/html"
* req.accepts(['json', 'text'])
* // => "json"
* req.accepts('application/json')
* // => "application/json"
*
* // Accept: text/*, application/json
* req.accepts('image/png')
* req.accepts('png')
* // => false
*
* // Accept: text/*;q=.5, application/json
* req.accepts(['html', 'json'])
* // => "json"
* ```
*
* For more information, or if you have issues or concerns, see
* [accepts](https://github.com/expressjs/accepts).
*/
accepts(types: string | Array<string>): string | Array<string> | null
/**
* Returns the specified HTTP request header field (case-insensitive match).
* The `Referrer` and `Referer` fields are interchangeable.
*
* ```javascript
* req.get('Content-Type')
* // => "text/plain"
*
* req.get('content-type')
* // => "text/plain"
*
* req.get('Something')
* // => undefined
* ```
*
* Aliased as `req.header(field)`.
*/
get(field: string): string | Buffer
header(field: string): string | Buffer
/**
* Contains a string corresponding to the HTTP method of the request: `GET`,
* `POST`, `PUT`, and so on.
*/
get method(): string
get params(): object
/**
* Range header parser.
*
* The size parameter is the maximum size of the resource.
*
* The options parameter is an object that can have the following properties.
*
* | Property | Type | Description |
* | --- | --- | --- |
* | combine | Boolean | Specify if overlapping & adjacent ranges should be
* | | | combined, defaults to false. When true, ranges will be combined and |
* | | | returned as if they were specified that way in the header. |
*
* An array of ranges will be returned or negative numbers indicating an error parsing.
*
* - `-2` signals a malformed header string
* - `-1` signals an unsatisfiable range
*
* ```javascript
* // parse header from request
* const range = req.range(1000)
*
* // the type of the range
* if (range.type === 'bytes') {
* // the ranges
* range.forEach((r) => {
* // do something with r.start and r.end
* })
* }
* ```
*/
range(size: number, options?: RangeOptions | undefined | null): number | Ranges | null
/**
* Included for test purposes. Normally, you will obtain a request from the
* server
*/
constructor()
/**
* `req.body`'s shape is based on user-controlled input, all properties and
* values in this object are untrusted and should be validated before
* trusting. For example, `req.body.foo.toString()` may fail in multiple
* ways, for example the foo property may not be there or may not be a
* string, and `toString` may not be a function and instead a string or
* other user input.
*/
get body(): string | unknown | Buffer | undefined
get cookies(): unknown | undefined
}
export declare class Response {
/**
* Appends the specified value to the HTTP response header field. If the header is not already set, it creates the header
* with the specified value. The value parameter can be a string or an array.
* > **➫ Note**
* >
* > calling `res.set()` after `res.append()` will reset the previously-set header value.
*
* ```javascript
* res.append('Link', ['<http://localhost/>', '<http://localhost:3000/>'])
* res.append('Set-Cookie', 'foo=bar; Path=/; HttpOnly')
* res.append('Warning', '199 Miscellaneous warning')
* ```
*/
append(field: string, value: Array<string> | string): void
/**
* Sets the HTTP response Content-Disposition header field to "attachment". If a file_path is given, then it sets the
* Content-Type based on the extension name via res.type(), and sets the Content-Disposition "filename=" parameter.
*
* ```javascript
* res.attachment()
* // Content-Disposition: attachment
*
* res.attachment('path/to/logo.png')
* // Content-Disposition: attachment; filename="logo.png"
* // Content-Type: image/png
* ```
*/
attachment(filePath?: string | undefined | null): void
/**
* Clears the cookie with the specified name by sending a `Set-Cookie` header that sets its expiration date in the past.
* This instructs the client that the cookie has expired and is no longer valid. For more information about available
* options, see `res.cookie()`.
*
* > The expires and max-age options are being ignored completely.
*
* > Web browsers and other compliant clients will only clear the cookie if the given options is identical to those given
* > to res.cookie()
*
* ```javascript
* res.cookie('name', 'tobi', { path: '/admin' })
* res.clearCookie('name', { path: '/admin' })
* ```
*/
clearCookie(name: string, options?: CookieOptions | undefined | null): void
/**
* Sets the `Content-Type` HTTP header to the MIME type as determined by the specified
* `type`. If `type` contains the "/" character, then it sets the `Content-Type` to
* the exact value of `type`, otherwise it is assumed to be a file extension and the
* MIME type is looked up using the `from_ext()` method of the mime_guess crate. When
* no mapping is found though `mime_guess::from_ext()`, the type is set to
* "application/octet-stream".
*
* Examples:
*
* ```javascript
* res.type('.html'); // => 'text/html'
* res.type('html'); // => 'text/html'
* res.type('json'); // => 'application/json'
* res.type('application/json'); // => 'application/json'
* res.type('png'); // => image/png
* ```
*
* Aliased as `res.contentType(type)`.
*/
type(typ: string): void
contentType(typ: string): void
/**
* Sets cookie `name` to `value`. The `value` parameter may be a string or object converted to JSON.
*
* The `options` parameter is an object that can have the following properties.
*
* | Property | Type | Description |
* | -------- | ----- | --- |
* | `domain` | String | Domain name for the cookie. Defaults to the domain name of the app. |
* | `encode` | Function | A synchronous function used for cookie value encoding. Defaults to `encodeURIComponent`. |
* | `expires` | Date | Expiry date of the cookie in GMT. If not specified or set to 0, creates a session cookie. |
* | `httpOnly` | Boolean | Flags the cookie to be accessible only by the web server. |
* | `maxAge` | Number | Convenient option for setting the expiry time relative to the current time in milliseconds. |
* | `path` | String | Path for the cookie. Defaults to "/". |
* | `partitioned` | Boolean | Indicates that the cookie should be stored using partitioned storage. See [Cookies Having Independent Partitioned State (CHIPS)](https://developer.mozilla.org/en-US/docs/Web/Privacy/Partitioned_cookies) for more details. |
* | `priority` | String | Value of the "Priority" Set-Cookie attribute. |
* | `secure` | Boolean | Marks the cookie to be used with HTTPS only. |
* | `signed` | Boolean | Indicates if the cookie should be signed. |
* | `sameSite` | Boolean or String | Value of the "SameSite" Set-Cookie attribute. More information at https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-00#section-4.1.1. |
*
* > All `res.cookie()` does is set the HTTP `Set-Cookie` header with the options provided. Any option not specified defaults to the value stated in [RFC 6265](http://tools.ietf.org/html/rfc6265).
*
* For example:
*
* ```javascript
* res.cookie('name', 'tobi', { domain: '.example.com', path: '/admin', secure: true })
* res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true })
* ```
*
* You can set multiple cookies in a single response by calling res.cookie multiple times, for example:
*
* ```javascript
* res
* .status(201)
* .cookie('access_token', `Bearer ${token}`, {
* expires: new Date(Date.now() + 8 * 3600000) // cookie will be removed after 8 hours
* })
* .cookie('test', 'test')
* .redirect(301, '/admin')
* ```
*
* The encode option allows you to choose the function used for cookie value encoding. Does not support asynchronous functions.
*
* Example use case: You need to set a domain-wide cookie for another site in your organization. This other site (not under your administrative control) does not use URI-encoded cookie values.
*
* ```javascript
* // Default encoding
* res.cookie('some_cross_domain_cookie', 'http://mysubdomain.example.com', { domain: 'example.com' })
* // Result: 'some_cross_domain_cookie=http%3A%2F%2Fmysubdomain.example.com; Domain=example.com; Path=/'
*
* // Custom encoding
* res.cookie('some_cross_domain_cookie', 'http://mysubdomain.example.com', { domain: 'example.com', encode: String })
* // Result: 'some_cross_domain_cookie=http://mysubdomain.example.com; Domain=example.com; Path=/;'
* ```
*
* The maxAge option is a convenience option for setting "expires" relative to the current time in milliseconds. The following is equivalent to the second example above.
*
* ```javascript
* res.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true })
* ```
*
* You can pass an object as the value parameter; it is then serialized as JSON and parsed by bodyParser() middleware.
*
* ```javascript
* res.cookie('cart', { items: [1, 2, 3] })
* res.cookie('cart', { items: [1, 2, 3] }, { maxAge: 900000 })
* ```
*
* When using cookie-parser middleware, this method also supports signed cookies. Simply include the signed option set to true. Then, res.cookie() will use the secret passed to cookieParser(secret) to sign the value.
*
* ```javascript
* res.cookie('name', 'tobi', { signed: true })
* ```
*
* Later, you may access this value through the `req.signedCookies` object.
*/
cookie(name: string, value: string, options?: CookieOptions | undefined | null): void
/**
* Transfers the file at `path` as an "attachment". Typically, browsers will
* prompt the user for download. By default, the `Content-Disposition`
* header "filename=" parameter is derived from the `path` argument, but can
* be overridden with the `filename` parameter. If `path` is relative, then
* it will be based on the current working directory of the process or the
* `root` option, if provided.
*
* > This API provides access to data on the running file system. Ensure
* > that either (a) the way in which the `path` argument was constructed
* > into an absolute path is secure if it contains user input or (b) set
* > the `root` option to the absolute path of a directory to contain access
* > within.
* >
* > When the `root` option is provided, the `path` argument is allowed to
* > be a relative path, including containing `..`. Express will validate
* > that the relative path provided as `path` will resolve within the given
* > `root` option.
*
* The following table provides details on the options parameter.
*
* | Property | Description | Default |
* | --- | --- | --- |
* | `maxAge` | Sets the max-age property of the `Cache-Control` header in milliseconds or a string in [ms format](https://www.npmjs.org/package/ms) | 0 |
* | `root` | Root directory for relative filenames. | |
* | `lastModified` | Sets the `Last-Modified` header to the last modified date of the file on the OS. Set `false` to disable it. | Enabled |
* | `headers` | Object containing HTTP headers to serve with the file. | |
* | `dotfiles` | Option for serving dotfiles. Possible values are "allow", "deny", "ignore". | "ignore" |
* | `acceptRanges` | Enable or disable accepting ranged requests. | true |
* | `cacheControl` | Enable or disable setting `Cache-Control` response header. | true |
* | `immutable` | Enable or disable the `immutable` directive in the `Cache-Control` response header. If enabled, the `maxAge` option should also be specified to enable caching. The `immutable` directive will prevent supported clients from making conditional requests during the life of the `maxAge` option to check if the file has changed. | false |
*
* The method invokes the callback function `fn(err)` when the transfer is
* complete or when an error occurs. If the callback function is specified
* and an error occurs, the callback function must explicitly handle the
* response process either by ending the request-response cycle, or by
* passing control to the next route.
*
* Here is an example of using `res.sendFile` with all its arguments.
*
* ```javascript
* res.download('/report-12345.pdf')
*
* res.download('/report-12345.pdf', 'report.pdf')
*
* res.download('/report-12345.pdf', 'report.pdf', (err) => {
* if (err) {
* // Handle error, but keep in mind the response may be partially-sent
* // so check res.headersSent
* } else {
* // decrement a download credit, etc.
* }
* })
*
* ```
*/
download(path: string, options?: DownloadOptions | undefined | null): Promise<unknown>
/**
* Performs content-negotiation on the Accept HTTP header on the request
* object, when present. It uses `req.accepts()` to select a handler for the
* request, based on the acceptable types ordered by their quality values.
* If the header is not specified, the first callback is invoked. When no
* match is found, the server responds with 406 "Not Acceptable", or invokes
* the default callback.
*
* The `Content-Type` response header is set when a callback is selected.
* However, you may alter this within the callback using methods such as
* `res.set()` or `res.type()`.
*
* The following example would respond with `{ "message": "hey" }` when the
* Accept header field is set to "application/json" or "*​/json" (however, if
* it is "*​/*", then the response will be "hey").
*
* ```javascript
* res.format({
* 'text/plain' () {
* res.send('hey')
* },
*
* 'text/html' () {
* res.send('<p>hey</p>')
* },
*
* 'application/json' () {
* res.send({ message: 'hey' })
* },
*
* default () {
* // log the request and respond with 406
* res.status(406).send('Not Acceptable')
* }
* })
* ```
*
* In addition to canonicalized MIME types, you may also use extension names
* mapped to these types for a slightly less verbose implementation:
*
* ```javascript
* res.format({
* text () {
* res.send('hey')
* },
*
* html () {
* res.send('<p>hey</p>')
* },
*
* json () {
* res.send({ message: 'hey' })
* }
* })
* ```
*/
format(obj: object): Response
/**
* Returns the HTTP response header specified by `field`. The match is case-insensitive.
*
* ```javascript
* res.get('Content-Type')
* // => "text/plain"
* ```
*/
get(field: string): string | Buffer
/**
* Sends a JSON response. This method sends a response (with the correct
* content-type) that is the parameter converted to a JSON string using
* JSON.stringify().
*
* The parameter can be any JSON type, including object, array, string,
* Boolean, number, or null, and you can also use it to convert other values
* to JSON.
*
* ```javascript
* res.json(null)
* res.json({ user: 'tobi' })
* res.status(500).json({ error: 'message' })
* ```
*/
json(body: string | number | boolean | object | null): void
/**
* Joins the links provided as properties of the parameter to populate the response’s Link HTTP header field.
*
* For example, the following call:
*
* ```javascript
* res.links({
* next: 'http://api.example.com/users?page=2',
* last: 'http://api.example.com/users?page=5'
* })
* ```
*
* Yields the following results:
*
* ```text
* Link: <http://api.example.com/users?page=2>; rel="next",
* <http://api.example.com/users?page=5>; rel="last"
* ```
*/
links(links: object): void
/**
* Sets the response Location HTTP header to the specified path parameter.
*
* ```javascript
* res.location('/foo/bar')
* res.location('http://example.com')
* ```
*
* > After encoding the URL, if not encoded already, the specified URL is
* > passed to the browser in the Location header, without any validation.
* >
* > Browsers take the responsibility of deriving the intended URL from the
* > current URL or the referring URL, and the URL specified in the Location
* > header; and redirect the user accordingly.
*
* The given `url` can also be "back", which redirects to the _Referrer_ or
* _Referer_ headers or "/".
*/
location(url: string): Response
/**
* Redirects to the URL derived from the specified `path`, with specified
* `status`, a positive integer that corresponds to an
* [HTTP status code](https://www.rfc-editor.org/rfc/rfc9110.html#name-status-codes).
* If not specified, `status` defaults to `302 "Found"`.
*
* ```javascript
* res.redirect('/foo/bar')
* res.redirect('http://example.com')
* res.redirect(301, 'http://example.com')
* res.redirect('../login')
* ```
*
* Redirects can be a fully-qualified URL for redirecting to a different site:
*
* ```javascript
* res.redirect('http://google.com')
* ```
*
* Redirects can be relative to the root of the host name. For example, if
* the application is on `http://example.com/admin/post/new`, the following
* would redirect to the URL `http://example.com/admin`:
*
* ```javascript
* res.redirect('/admin')
* ```
*
* Redirects can be relative to the current URL. For example, from
* `http://example.com/blog/admin/` (notice the trailing slash), the
* following would redirect to the URL
* `http://example.com/blog/admin/post/new`.
*
* ```javascript
* res.redirect('post/new')
* ```
*
* Redirecting to `post/new` from `http://example.com/blog/admin` (no
* trailing slash), will redirect to `http://example.com/blog/post/new`.
*
* If you found the above behavior confusing, think of path segments as
* directories (with trailing slashes) and files, it will start to make
* sense.
*
* Path-relative redirects are also possible. If you were on
* `http://example.com/admin/post/new`, the following would redirect to
* `http://example.com/admin/post`:
*
* ```javascript
* res.redirect('..')
* ```
*
* See also [Security best practices: Prevent open redirect vulnerabilities](http://expressjs.com/en/advanced/best-practice-security.html#prevent-open-redirects).
*/
redirect(status: number | string, address?: string | undefined | null): void
/**
* Sends the HTTP response.
*
* The body parameter can be a Buffer object, a String, an object, Boolean, or
* an Array. For example:
*
* ```javascript
* res.send(Buffer.from('whoop'))
* res.send({ some: 'json' })
* res.send('<p>some html</p>')
* res.status(404).send('Sorry, we cannot find that!')
* res.status(500).send({ error: 'something blew up' })
* ```
*
* This method performs many useful tasks for simple non-streaming responses:
* For example, it automatically assigns the Content-Length HTTP response
* header field and provides automatic HEAD and HTTP cache freshness support.
*
* When the parameter is a Buffer object, the method sets the Content-Type
* response header field to "application/octet-stream", unless previously
* defined as shown below:
*
* ```javascript
* res.set('Content-Type', 'text/html')
* res.send(Buffer.from('<p>some html</p>'))
* ```
*
* When the parameter is a String, the method sets the Content-Type to
* "text/html":
*
* ```javascript
* res.send('<p>some html</p>')
* ```
*
* When the parameter is an Array or Object, Express responds with the JSON
* representation:
*
* ```javascript
* res.send({ user: 'tobi' })
* res.send([1, 2, 3])
* ```
*/
send(body: string | number | boolean | null | Buffer | object): void
/**
* Transfers the file at the given `path`. Sets the `Content-Type` response
* HTTP header field based on the filename’s extension. Unless the `root`
* option is set in the options object, `path` must be an absolute path to
* the file.
*
* > This API provides access to data on the running file system. Ensure
* > that either (a) the way in which the `path` argument was constructed
* > into an absolute path is secure if it contains user input or (b) set
* > the `root` option to the absolute path of a directory to contain access
* > within.
* >
* > When the `root` option is provided, the `path` argument is allowed to
* > be a relative path, including containing `..`. Express will validate
* > that the relative path provided as `path` will resolve within the given
* > `root` option.
*
* The following table provides details on the options parameter.
*
* | Property | Description | Default |
* | --- | --- | --- |
* | `maxAge` | Sets the max-age property of the `Cache-Control` header in milliseconds or a string in [ms format](https://www.npmjs.org/package/ms) | 0 |
* | `root` | Root directory for relative filenames. | |
* | `lastModified` | Sets the `Last-Modified` header to the last modified date of the file on the OS. Set `false` to disable it. | Enabled |
* | `headers` | Object containing HTTP headers to serve with the file. | |
* | `dotfiles` | Option for serving dotfiles. Possible values are "allow", "deny", "ignore". | "ignore" |
* | `acceptRanges` | Enable or disable accepting ranged requests. | true |
* | `cacheControl` | Enable or disable setting `Cache-Control` response header. | true |
* | `immutable` | Enable or disable the `immutable` directive in the `Cache-Control` response header. If enabled, the `maxAge` option should also be specified to enable caching. The `immutable` directive will prevent supported clients from making conditional requests during the life of the `maxAge` option to check if the file has changed. | false |
*
* The method invokes the callback function `fn(err)` when the transfer is
* complete or when an error occurs. If the callback function is specified
* and an error occurs, the callback function must explicitly handle the
* response process either by ending the request-response cycle, or by
* passing control to the next route.
*
* Here is an example of using `res.sendFile` with all its arguments.
*
* ```javascript
* app.get('/file/:name', (req, res, next) => {
* const options = {
* root: path.join(__dirname, 'public'),
* dotfiles: 'deny',
* headers: {
* 'x-timestamp': Date.now(),
* 'x-sent': true
* }
* }
*
* const fileName = req.params.name
* res.sendFile(fileName, options, (err) => {
* if (err) {
* next(err)
* } else {
* console.log('Sent:', fileName)
* }
* })
* })
* ```
*
* The following example illustrates using `res.sendFile` to provide
* fine-grained support for serving files:
*
* ```javascript
* app.get('/user/:uid/photos/:file', (req, res) => {
* const uid = req.params.uid
* const file = req.params.file
*
* req.user.mayViewFilesFrom(uid, (yes) => {
* if (yes) {
* res.sendFile(`/uploads/${uid}/${file}`)
* } else {
* res.status(403).send("Sorry! You can't see that.")
* }
* })
* })
* ```
*
* For more information, or if you have issues or concerns, see
* [send](https://github.com/pillarjs/send).
*/
sendFile(path: string, options?: SendFileOptions | undefined | null): Promise<unknown>
/**
* Sets the response HTTP status code to statusCode and sends the registered
* status message as the text response body. If an unknown status code is
* specified,`res.statusCode` will throw an error
*
* ```javascript
* res.sendStatus(404)
* ```
*/
sendStatus(body: number | StatusCode): void
/**
* Sets the response’s HTTP header field to value. To set multiple fields at
* once, pass an object as the parameter.
*
* ```javascript
* res.set('Content-Type', 'text/plain')
*
* res.set({
* 'Content-Type': 'text/plain',
* 'Content-Length': '123',
* ETag: '12345',
* Link: ['<http://localhost/>', '<http://localhost:3000/>']
* })
* ```
*
* Aliased as res.header(field [, value]).
*/
set(field: string | object, value?: string | undefined | null): Response
/**
* Sets the HTTP status for the response.
*
* ```javascript
* res.status(403).end()
* res.status(400).send('Bad Request')
* res.status(404).sendFile('/absolute/path/to/404.png')
* ```
*/
status(body: number | StatusCode): Response
/**
* Adds the field to the `Vary` response header, if it is not there already.
*
* ``` javascript
* res.vary('User-Agent').render('docs')
* ```
*/
vary(field: string): void
constructor()
end(data?: string | Buffer | Uint8Array | undefined | null): void
get req(): Request
}
/** HTTP Server that integrates with JavaScript handlers via Router */
export declare class Server {
/** Create a new server with a router */
constructor()
delete(route: string, handler: JsHandlerFn): void
get(route: string, handler: JsHandlerFn): void
post(route: string, handler: JsHandlerFn): void
put(route: string, handler: JsHandlerFn): void
use(route: string | undefined | null, middleware: JsHandlerFn): void
acmeConfigMeta(config: AcmeConfigMeta): void
listen(addr: string): void
}
/**
* This is a built-in middleware function. It serves static files and is based
* on [hyper-staticfile](https://docs.rs/hyper-staticfile/latest/hyper_staticfile/).
*
* > NOTE: For best results,
* > [use a reverse proxy](https://expressjs.com/en/advanced/best-practice-performance.html#use-a-reverse-proxy)
* > cache to improve performance of serving static assets.
*
* The `root` argument specifies the root directory from which to serve static
* assets. The function determines the file to serve by combining `req.url`
* with the provided `root` directory. When a file is not found, instead of
* sending a 404 response, it instead calls `next()` to move on to the next
* middleware, allowing for stacking and fall-backs.
*
* Example of using the StaticMiddleware
* Here is an example of using the Static middleware with an elaborate options object:
*
* ```javascript
* const options = {
* dotfiles: 'ignore',
* etag: false,
* extensions: ['htm', 'html'],
* index: false,
* maxAge: '1d',
* redirect: false,
* setHeaders (res, path, stat) {
* res.set('x-timestamp', Date.now())
* }
* }
*
* app.use(new StaticMiddleware('public', options))
* ```
*/
export declare class StaticMiddleware {
constructor(root: string, options?: JsStaticOptions | undefined | null)
run(request: Request, response: Response): Promise<unknown>
}
export declare class StatusCode {
static fromU16(src: number): StatusCode
static fromBytes(src: Uint8Array): StatusCode
toString(): string
canonicalReason(): string | null
isInformational(): boolean
isSuccess(): boolean
isRedirection(): boolean
isClientError(): boolean
static continue(): StatusCode
static switchingProtocols(): StatusCode
static processing(): StatusCode
static ok(): StatusCode
static created(): StatusCode
static accepted(): StatusCode
static nonAuthoritativeInformation(): StatusCode
static noContent(): StatusCode
static resetContent(): StatusCode
static partialContent(): StatusCode
static multiStatus(): StatusCode
static alreadyReported(): StatusCode
static imUsed(): StatusCode
static multipleChoices(): StatusCode
static movedPermanently(): StatusCode
static found(): StatusCode
static seeOther(): StatusCode
static notModified(): StatusCode
static useProxy(): StatusCode
static temporaryRedirect(): StatusCode
static permanentRedirect(): StatusCode
static badRequest(): StatusCode
static unauthorized(): StatusCode
static paymentRequired(): StatusCode
static forbidden(): StatusCode
static notFound(): StatusCode
static methodNotAllowed(): StatusCode
static notAcceptable(): StatusCode
static proxyAuthenticationRequired(): StatusCode
static requestTimeout(): StatusCode
static conflict(): StatusCode
static gone(): StatusCode
static lengthRequired(): StatusCode
static preconditionFailed(): StatusCode
static payloadTooLarge(): StatusCode
static uriTooLong(): StatusCode
static unsupportedMediaType(): StatusCode
static rangeNotSatisfiable(): StatusCode
static expectationFailed(): StatusCode
static imATeapot(): StatusCode
static misdirectedRequest(): StatusCode
static unprocessableEntity(): StatusCode
static locked(): StatusCode
static failedDependency(): StatusCode
static tooEarly(): StatusCode
static upgradeRequired(): StatusCode
static preconditionRequired(): StatusCode
static tooManyRequests(): StatusCode
static requestHeaderFieldsTooLarge(): StatusCode
static unavailableForLegalReasons(): StatusCode
static internalServerError(): StatusCode
static notImplemented(): StatusCode
static badGateway(): StatusCode
static serviceUnavailable(): StatusCode
static gatewayTimeout(): StatusCode
static httpVersionNotSupported(): StatusCode
static variantAlsoNegotiates(): StatusCode
static insufficientStorage(): StatusCode
static loopDetected(): StatusCode
static notExtended(): StatusCode
static networkAuthenticationRequired(): StatusCode
}
/**
* This is a built-in middleware function in Express. It parses incoming
* request payloads into a string.
*
* Returns middleware that parses all bodies as a string and only looks at
* requests where the `Content-Type` header matches the `type` option. This
* parser accepts any Unicode encoding of the body and supports automatic
* inflation of `gzip` and `deflate` encodings.
*
* A new `body` string containing the parsed data is populated on the
* `request` object after the middleware (i.e. `req.body`), or `undefined` if
* there was no body to parse, the `Content-Type` was not matched, or an error
* occurred.
*
* > As `req.body`’s shape is based on user-controlled input, all properties
* > and values in this object are untrusted and should be validated before
* > trusting. For example, `req.body.trim()` may fail in multiple ways, for
* > example stacking multiple parsers `req.body` may be from a different
* > parser. Testing that `req.body` is a string before calling string methods
* > is recommended.
*/
export declare class TextMiddleware {
constructor(options?: JsTextOptions | undefined | null)
run(request: Request, response: Response): Promise<boolean>
}
/**
* This is a built-in middleware function in Express. It parses incoming
* requests with urlencoded payloads.
*
* Returns middleware that only parses urlencoded bodies and only looks at
* requests where the `Content-Type` header matches the `type` option. This
* parser accepts only UTF-8 encoding of the body and supports automatic
* inflation of `gzip` and `deflate` encodings.
*
* A new `body` object containing the parsed data is populated on the
* `request` object after the middleware (i.e. `req.body`), or `undefined` if
* there was no body to parse, the `Content-Type` was not matched, or an error
* occurred. This object will contain key-value pairs, where the value can be
* a string or array (when `extended` is `false`), or any type (when
* `extended` is `true`).
*
* > As `req.body`’s shape is based on user-controlled input, all properties
* > and values in this object are untrusted and should be validated before
* > trusting. For example, `req.body.foo.toString()` may fail in multiple
* > ways, for example `foo` may not be there or may not be a string, and
* > `toString` may not be a function and instead a string or other
* > user-input.
*/
export declare class UrlencodedMiddleware {
constructor(options?: JsUrlencodedOptions | undefined | null)
run(request: Request, response: Response): Promise<boolean>
}
export declare class Version {
static http09(): Version
static http10(): Version
static http11(): Version
static http2(): Version
static http3(): Version
}
export interface AcmeConfigMeta {
domains: Array<string>
contactEmail: string
cacheDir: string
}
export interface ClearCookie {
}
export interface CookieOptions {
domain?: string
encode?: (arg: string) => string
expires?: Date | ClearCookie
httpOnly?: boolean
maxAge?: number
path?: string
partitioned?: boolean
priority?: string
secure?: boolean
signed?: boolean
sameSite?: boolean | string
}
export interface DownloadOptions {
maxAge?: number
root?: string
lastModified?: boolean
headers?: object
dotfiles?: string
acceptRanges?: boolean
cacheControl?: boolean
immutable?: boolean
}
export interface JsCookieParserOptions {
/**
* If `true`, the cookie value will be percent-decoded
*
* A cookie whose value is `foo=bar%20baz; HttpOnly` gets parsed into the
* name-value pair `"foo", "bar baz"`
*/
percentDecode?: boolean
}
export interface JsJsonOptions {
/**
* Enables or disables handling deflated (compressed) bodies; when disabled,
* deflated bodies are rejected.
*
* Default = true
*/