MCPcopy Index your code
hub / github.com/restify/node-restify / serverMethodFactory

Function serverMethodFactory

lib/server.js:1756–1784  ·  view source on GitHub ↗

* Mounts a chain on the given path against this HTTP verb * * @private * @function serverMethodFactory * @param {String} method - name of the HTTP method * @returns {Function} factory

(method)

Source from the content-addressed store, hash-verified

1754 * @returns {Function} factory
1755 */
1756function serverMethodFactory(method) {
1757 return function serverMethod(opts) {
1758 if (opts instanceof RegExp || typeof opts === 'string') {
1759 opts = {
1760 path: opts
1761 };
1762 } else if (typeof opts === 'object') {
1763 opts = shallowCopy(opts);
1764 } else {
1765 throw new TypeError('path (string) required');
1766 }
1767
1768 if (arguments.length < 2) {
1769 throw new TypeError('handler (function) required');
1770 }
1771
1772 opts.method = method;
1773 opts.path = opts.path || opts.url;
1774
1775 // We accept both a variable number of handler functions, a
1776 // variable number of nested arrays of handler functions, or a mix
1777 // of both
1778 var handlers = Array.prototype.slice.call(arguments, 1);
1779 var chain = argumentsToChain(handlers);
1780 var route = this.router.mount(opts, chain);
1781
1782 return route.name;
1783 };
1784}

Callers 1

server.jsFile · 0.85

Calls 2

argumentsToChainFunction · 0.85
shallowCopyFunction · 0.70

Tested by

no test coverage detected