You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+22-10Lines changed: 22 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,17 +16,28 @@ $ npm install connect-timeout
16
16
17
17
## API
18
18
19
-
**NOTE** This module is not recommend as a "top-level" middleware (i.e. `app.use(timeout('5s'))`) unless
20
-
you take precautions to halt your own middleware processing. See [as top-level middleware](#as-top-level-middleware)
19
+
**NOTE** This module is not recommend as a "top-level" middleware (i.e.
20
+
`app.use(timeout('5s'))`) unless you take precautions to halt your own
21
+
middleware processing. See [as top-level middleware](#as-top-level-middleware)
21
22
for how to use as a top-level middleware.
22
23
23
-
### timeout(time, options)
24
+
### timeout(time, [options])
24
25
25
-
Returns middleware that times out in `time` milliseconds. `time` can also be a string accepted by the [ms](https://www.npmjs.org/package/ms#readme) module. On timeout, `req` will emit `"timeout"`.
26
+
Returns middleware that times out in `time` milliseconds. `time` can also
27
+
be a string accepted by the [ms](https://www.npmjs.org/package/ms#readme)
28
+
module. On timeout, `req` will emit `"timeout"`.
26
29
27
-
#### options
30
+
#### Options
28
31
29
-
*`respond` - If `true`, the timeout error is passed to `next()` so that you may customize the response behavior. This error has a `.timeout` property as well as `.status == 503`. This defaults to `true`.
32
+
The `timeout` function takes an optional `options` object that may contain
33
+
any of the following keys:
34
+
35
+
##### respond
36
+
37
+
Controls if this module will "respond" in the form of forwarding an error.
38
+
If `true`, the timeout error is passed to `next()` so that you may customize
39
+
the response behavior. This error has a `.timeout` property as well as
40
+
`.status == 503`. This defaults to `true`.
30
41
31
42
### req.clearTimeout()
32
43
@@ -40,10 +51,11 @@ Clears the timeout on the request.
40
51
41
52
### as top-level middleware
42
53
43
-
Because of the way middleware processing works, this once this module passes the request
44
-
to the next middleware (which it has to do in order for you to do work), it can no longer
45
-
stop the flow, so you must take care to check if the request has timedout before you
46
-
continue to act on the request.
54
+
Because of the way middleware processing works, this once this module
55
+
passes the request to the next middleware (which it has to do in order
56
+
for you to do work), it can no longer stop the flow, so you must take
57
+
care to check if the request has timedout before you continue to act
0 commit comments