Skip to content

Commit a44856f

Browse files
committed
adding timeout and unavailability docs
1 parent 26147ba commit a44856f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ service.start(3000)
4242
middlewares: [],
4343
// Optional global value for routes "pathRegex". Default value: '/*'
4444
pathRegex: '/*',
45+
// Optional global requests timeout value (given in milliseconds). Default value: '0' (DISABLED)
46+
timeout: 0,
4547
// Optional "target" value that overrides the routes "target" config value. Feature intended for testing purposes.
4648
targetOverride: "https://yourdev.api-gateway.com",
4749

@@ -50,11 +52,15 @@ service.start(3000)
5052
// Optional `fast-proxy` library configuration (https://www.npmjs.com/package/fast-proxy#options)
5153
// base parameter defined as the route target. Default value: {}
5254
fastProxy: {},
55+
// Optional proxy handler function. Default value: (req, res, url, proxy, proxyOpts) => proxy(req, res, url, proxyOpts)
56+
proxyHandler: () => {}
5357
// Optional flag to indicate if target uses the HTTP2 protocol. Default value: false
5458
http2: false,
5559
// Optional path matching regex. Default value: '/*'
5660
// In order to disable the 'pathRegex' at all, you can use an empty string: ''
5761
pathRegex: '/*',
62+
// Optional service requests timeout value (given in milliseconds). Default value: '0' (DISABLED)
63+
timeout: 0,
5864
// route prefix
5965
prefix: '/public',
6066
// Optional documentation configuration (unrestricted schema)
@@ -133,6 +139,19 @@ Example output:
133139
```
134140
> NOTE: Please see `docs` configuration entry explained above.
135141
142+
## Timeouts and Unavailability
143+
We can restrict requests timeouts globally, at service level using the `timeout` configuration.
144+
To define an endpoint specific timeout, you can use the property `timeout` of the request object, normally inside a middleware:
145+
```js
146+
req.timeout = 500 // define a 500ms timeout on a custom request.
147+
```
148+
> NOTE: You might want to also check https://www.npmjs.com/package/middleware-if-unless
149+
150+
### Circuit Breaker
151+
By using the `proxyHandler` hook, developers can optionally intercept and modify the default gateway routing behavior right before the origin request is proxied to the remote service. Therefore, connecting advanced monitoring mechanisms like [Circuit Breakers](https://martinfowler.com/bliki/CircuitBreaker.html) is rather simple.
152+
153+
Please see the `demos/circuitbreaker.js` example for more details using the `opossum` library.
154+
136155
## Gateway level caching
137156
Caching support is provided by the `http-cache-middleware` module. https://www.npmjs.com/package/http-cache-middleware
138157

0 commit comments

Comments
 (0)