Skip to content

Commit 09b46dc

Browse files
Peter Martonhekike
Peter Marton
authored andcommitted
docs(api): regenerate
1 parent 01fd28f commit 09b46dc

File tree

4 files changed

+96
-49
lines changed

4 files changed

+96
-49
lines changed

docs/_api/plugins.md

+78-7
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ permalink: /docs/plugins-api/
3131
- [Using an external storage mechanism for key/bucket mappings.](#using-an-external-storage-mechanism-for-keybucket-mappings)
3232
- [inflightRequestThrottle](#inflightrequestthrottle)
3333
- [cpuUsageThrottle](#cpuusagethrottle)
34+
- [conditionalHandler](#conditionalhandler)
3435
- [conditionalRequest](#conditionalrequest)
3536
- [auditLogger](#auditlogger)
3637
- [metrics](#metrics)
@@ -534,7 +535,7 @@ _The serveStatic module is different than most of the other plugins, in that
534535
it is expected that you are going to map it to a route, as below:_
535536

536537
```javascript
537-
server.get(/\/docs\/current\/?.*\//, restify.plugins.serveStatic({
538+
server.get('/docs/current/*', restify.plugins.serveStatic({
538539
directory: './documentation/v1',
539540
default: 'index.html'
540541
}));
@@ -562,7 +563,12 @@ serveStatic method as an option. The following will serve index.html from
562563
the documentation/v1/ directory anytime a client requests `/home/`._
563564

564565
```javascript
565-
server.get(/\/home\//, restify.plugins.serveStatic({
566+
server.get('/home/*', restify.plugins.serveStatic({
567+
directory: './documentation/v1',
568+
file: 'index.html'
569+
}));
570+
// or
571+
server.get('/home/([a-z]+[.]html)', restify.plugins.serveStatic({
566572
directory: './documentation/v1',
567573
file: 'index.html'
568574
}));
@@ -853,6 +859,66 @@ plugin.update({ limit: .4, halfLife: 5000 });
853859
854860
Returns **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** middleware to be registered on server.pre
855861
862+
### conditionalHandler
863+
864+
Runs first handler that matches to the condition
865+
866+
**Parameters**
867+
868+
- `candidates` **([Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)>)** candidates
869+
- `candidates.handler` **([Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)>)** handler(s)
870+
- `candidates.version` **([String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>)?** '1.1.0', ['1.1.0', '1.2.0']
871+
- `candidates.contentType` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** accepted content type, '\*\\/json'
872+
873+
**Examples**
874+
875+
```javascript
876+
server.use(restify.plugins.conditionalHandler({
877+
contentType: 'application/json',
878+
version: '1.0.0',
879+
handler: function (req, res, next) {
880+
next();
881+
})
882+
});
883+
884+
server.get('/hello/:name', restify.plugins.conditionalHandler([
885+
{
886+
version: '1.0.0',
887+
handler: function(req, res, next) { res.send('1.x'); }
888+
},
889+
{
890+
version: ['1.5.0', '2.0.0'],
891+
handler: function(req, res, next) { res.send('1.5.x, 2.x'); }
892+
},
893+
{
894+
version: '3.0.0',
895+
contentType: ['text/html', 'text/html']
896+
handler: function(req, res, next) { res.send('3.x, text'); }
897+
},
898+
{
899+
version: '3.0.0',
900+
contentType: 'application/json'
901+
handler: function(req, res, next) { res.send('3.x, json'); }
902+
},
903+
// Array of handlers
904+
{
905+
version: '4.0.0',
906+
handler: [
907+
function(req, res, next) { next(); },
908+
function(req, res, next) { next(); },
909+
function(req, res, next) { res.send('4.x') }
910+
]
911+
},
912+
]);
913+
// 'accept-version': '^1.1.0' => 1.5.x, 2.x'
914+
// 'accept-version': '3.x', accept: 'application/json' => '3.x, json'
915+
```
916+
917+
- Throws **InvalidVersionError**
918+
- Throws **UnsupportedMediaTypeError**
919+
920+
Returns **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Handler
921+
856922
### conditionalRequest
857923
858924
Returns a set of plugins that will compare an already set `ETag` header with
@@ -1079,16 +1145,21 @@ Type: [Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Sta
10791145
- `metrics.statusCode` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** status code of the response. can be
10801146
undefined in the case of an uncaughtException
10811147
- `metrics.method` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** http request verb
1082-
- `metrics.latency` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** request latency
1148+
- `metrics.totalLatency` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** latency includes both request is flushed
1149+
and all handlers finished
1150+
- `metrics.latency` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** latency when request is flushed
1151+
- `metrics.preLatency` **([Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number) | null)** pre handlers latency
1152+
- `metrics.useLatency` **([Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number) | null)** use handlers latency
1153+
- `metrics.routeLatency` **([Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number) | null)** route handlers latency
10831154
- `metrics.path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** `req.path()` value
10841155
- `metrics.inflightRequests` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Number of inflight requests pending
10851156
in restify.
10861157
- `metrics.unifinishedRequests` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Same as `inflightRequests`
1087-
- `metrics.connectionState` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** can be either `'close'`,
1088-
`'aborted'`, or `undefined`. If this value is set, err will be a
1089-
corresponding `RequestCloseError` or `RequestAbortedError`.
1158+
- `metrics.connectionState` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** can be either `'close'` or
1159+
`undefined`. If this value is set, err will be a
1160+
corresponding `RequestCloseError`.
10901161
If connectionState is either
1091-
`'close'` or `'aborted'`, then the `statusCode` is not applicable since the
1162+
`'close'`, then the `statusCode` is not applicable since the
10921163
connection was severed before a response was written.
10931164
- `req` **[Request](https://developer.mozilla.org/Add-ons/SDK/High-Level_APIs/request)** the request obj
10941165
- `res` **[Response](https://developer.mozilla.org/docs/Web/Guide/HTML/HTML5)** the response obj

docs/_api/request.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,8 @@ Returns **[undefined](https://developer.mozilla.org/docs/Web/JavaScript/Referenc
356356
Returns the connection state of the request. Current possible values are:
357357

358358
- `close` - when the request has been closed by the clien
359-
- `aborted` - when the socket was closed unexpectedly
360359

361-
Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** connection state (`"closed"`, `"aborted"`)
360+
Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** connection state (`"close"`)
362361

363362
### getRoute
364363

docs/_api/server.md

+16-38
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ permalink: /docs/server-api/
2121
- [pre](#pre)
2222
- [use](#use)
2323
- [param](#param)
24-
- [versionedUse](#versioneduse)
2524
- [rm](#rm)
2625
- [address](#address)
2726
- [inflightRequests](#inflightrequests)
@@ -39,12 +38,11 @@ routes and handlers for incoming requests.
3938

4039
**Parameters**
4140

42-
- `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** an options object
41+
- `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** an options object
4342
- `options.name` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Name of the server. (optional, default `"restify"`)
43+
- `options.dtrace` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** enable DTrace support (optional, default `false`)
4444
- `options.router` **Router** Router (optional, default `newRouter(opts)`)
4545
- `options.log` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** [bunyan](https://github.com/trentm/node-bunyan) instance. (optional, default `bunyan.createLogger(options.name||"restify")`)
46-
- `options.version` **([String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array))?** Default version(s) to use in all
47-
routes.
4846
- `options.acceptable` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)?** String)|List of content-types this
4947
server can respond with.
5048
- `options.url` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Once listen() is called, this will be filled
@@ -59,7 +57,8 @@ routes and handlers for incoming requests.
5957
will use a domain to catch and respond to any uncaught
6058
exceptions that occur in it's handler stack.
6159
[bunyan](https://github.com/trentm/node-bunyan) instance.
62-
response header, default is `restify`. Pass empty string to unset the header. (optional, default `false`)
60+
response header, default is `restify`. Pass empty string to unset the header.
61+
Comes with significant negative performance impact. (optional, default `false`)
6362
- `options.spdy` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** Any options accepted by
6463
[node-spdy](https://github.com/indutny/node-spdy).
6564
- `options.http2` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** Any options accepted by
@@ -96,11 +95,10 @@ Creates a new Server.
9695

9796
- `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** an options object
9897
- `options.name` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Name of the server.
98+
- `options.dtrace` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** enable DTrace support (optional, default `false`)
9999
- `options.router` **Router** Router
100100
- `options.log` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** [bunyan](https://github.com/trentm/node-bunyan)
101101
instance.
102-
- `options.version` **([String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array))?** Default version(s) to use in all
103-
routes.
104102
- `options.acceptable` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>?** List of content-types this
105103
server can respond with.
106104
- `options.url` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Once listen() is called, this will be filled
@@ -114,6 +112,7 @@ Creates a new Server.
114112
- `options.handleUncaughtExceptions` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** When true restify
115113
will use a domain to catch and respond to any uncaught
116114
exceptions that occur in it's handler stack.
115+
Comes with significant negative performance impact.
117116
[bunyan](https://github.com/trentm/node-bunyan) instance.
118117
response header, default is `restify`. Pass empty string to unset the header. (optional, default `false`)
119118
- `options.spdy` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** Any options accepted by
@@ -123,13 +122,17 @@ Creates a new Server.
123122
- `options.handleUpgrades` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Hook the `upgrade` event
124123
from the node HTTP server, pushing `Connection: Upgrade` requests through the
125124
regular request handling chain. (optional, default `false`)
125+
- `options.onceNext` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Prevents calling next multiple
126+
times (optional, default `false`)
127+
- `options.strictNext` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Throws error when next() is
128+
called more than once, enabled onceNext option (optional, default `false`)
126129
- `options.httpsServerOptions` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** Any options accepted by
127130
[node-https Server](http://nodejs.org/api/https.html#https_https).
128131
If provided the following restify server options will be ignored:
129132
spdy, ca, certificate, key, passphrase, rejectUnauthorized, requestCert and
130133
ciphers; however these can all be specified on httpsServerOptions.
131-
- `options.strictRouting` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** If set, Restify
132-
will treat "/foo" and "/foo/" as different paths. (optional, default `false`)
134+
- `options.noWriteContinue` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** prevents
135+
`res.writeContinue()` in `server.on('checkContinue')` when proxing (optional, default `false`)
133136

134137
**Examples**
135138

@@ -340,37 +343,14 @@ Exposes an API:
340343

341344
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** returns self
342345

343-
### versionedUse
344-
345-
Piggy-backs on the `server.use` method. It attaches a new middleware
346-
function that only fires if the specified version matches the request.
347-
348-
Note that if the client does not request a specific version, the middleware
349-
function always fires. If you don't want this set a default version with a
350-
pre handler on requests where the client omits one.
351-
352-
Exposes an API:
353-
server.versionedUse("version", function (req, res, next, ver) {
354-
// do stuff that only applies to routes of this API version
355-
});
356-
357-
**Parameters**
358-
359-
- `versions` **([String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array))** the version(s) the URL to respond to
360-
- `fn` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** the middleware function to execute, the
361-
fourth parameter will be the selected
362-
version
363-
364-
Returns **[undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined)** no return value
365-
366346
### rm
367347

368348
Removes a route from the server.
369349
You pass in the route 'blob' you got from a mount call.
370350

371351
**Parameters**
372352

373-
- `route` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the route name.
353+
- `routeName` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the route name.
374354

375355

376356
- Throws **[TypeError](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/TypeError)** on bad input.
@@ -424,7 +404,6 @@ _Output:_
424404
input: '/',
425405
compiledRegex: /^[\/]*$/,
426406
compiledUrlParams: null,
427-
versions: null,
428407
handlers: [Array]
429408
}
430409
],
@@ -770,8 +749,8 @@ Type: ([String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Glob
770749
**Properties**
771750

772751
- `name` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a name for the route
773-
- `path` **([String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Regexp](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RegExp))** a string or regex matching the route
774-
- `version` **([String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>)** versions supported by this route
752+
- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** can be any String accepted by
753+
[find-my-way](https://github.com/delvedor/find-my-way)
775754

776755
**Examples**
777756

@@ -781,10 +760,9 @@ server.get('/foo', function(req, res, next) {});
781760
// a parameterized route
782761
server.get('/foo/:bar', function(req, res, next) {});
783762
// a regular expression
784-
server.get(/^\/([a-zA-Z0-9_\.~-]+)\/(.*)/, function(req, res, next) {});
763+
server.get('/example/:file(^\\d+).png', function(req, res, next) {});
785764
// an options object
786765
server.get({
787766
path: '/foo',
788-
version: ['1.0.0', '2.0.0']
789767
}, function(req, res, next) {});
790768
```

test/plugins/dedupeSlashes.test.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ describe('dedupe forward slashes in URL', function() {
6464
});
6565

6666
// eslint-disable-next-line
67-
it('should remove duplicate slashes including trailing slashes',
68-
function(done) {
67+
it('should remove duplicate slashes including trailing slashes', function(done) {
6968
CLIENT.get('//foo//bar//', function(err, _, res, data) {
7069
assert.ifError(err);
7170
assert.equal(res.statusCode, 200);

0 commit comments

Comments
 (0)