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

Function createServer

lib/index.js:73–106  ·  view source on GitHub ↗

* A restify server object is the main interface through which you will register * routes and handlers for incoming requests. * * @public * @function createServer * @param {Object} [options] - an options object * @param {String} [options.name="restify"] - Name of the server. * @param {Boolean

(options)

Source from the content-addressed store, hash-verified

71 * @returns {Server} server
72 */
73function createServer(options) {
74 assert.optionalObject(options, 'options');
75
76 var opts = shallowCopy(options || {});
77 var server;
78
79 // empty string should override default value.
80 opts.name = opts.hasOwnProperty('name') ? opts.name : 'restify';
81 opts.log = opts.log || pino({ name: opts.name || 'restify' });
82 opts.router = opts.router || new Router(opts);
83
84 server = new Server(opts);
85
86 if (opts.handleUncaughtExceptions) {
87 server.on('uncaughtException', function onUncaughtException(
88 req,
89 res,
90 route,
91 e
92 ) {
93 if (
94 this.listeners('uncaughtException').length > 1 ||
95 res.headersSent
96 ) {
97 return false;
98 }
99
100 res.send(new InternalError(e, e.message || 'unexpected error'));
101 return true;
102 });
103 }
104
105 return server;
106}
107
108///--- Exports
109

Callers

nothing calls this directly

Calls 1

shallowCopyFunction · 0.70

Tested by

no test coverage detected