Skip to content

Commit

Permalink
adding docs to the main server class
Browse files Browse the repository at this point in the history
  • Loading branch information
esatterwhite committed Dec 27, 2016
1 parent f366512 commit 242e359
Showing 1 changed file with 45 additions and 3 deletions.
48 changes: 45 additions & 3 deletions lib/server/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
/*jshint laxcomma: true, smarttabs: true, node: true, esnext: true*/
'use strict';
/**
* Primary server instance for a skyring app.
* @module skyring/lib/server
* @author Eric Satterwhite
* @since 1.0.0
* @requires http
* @requires debug
* @requires skyring/lib/server/mock
* @requires skyring/lib/server/node
* @requires skyring/lib/server/router
* @requires skyring/lib/timer
*/

const http = require('http')
, Debug = require('debug')
Expand All @@ -9,17 +22,31 @@ const http = require('http')
, debug = Debug('skyring:server')
;

/**
* Description
* @constructor
* @alias module:skyring/lib/server
* @param {Object} [options]
* @param {module:skyring/lib/server/node} [options.node] A customer node instance
* @example var server = new Server({})
server.load().listen(5000)
*/
class Server extends http.Server {
constructor( opts, node ){
constructor( opts ){
super((req, res) => {
this._router.handle(req, res)
});
this.loaded = false;
this._node = node || new Node();
this._node = opts.node || new Node();
this._router = new Router(this._node);
}

load(){
/**
 * loads application routes if not already loaded
 * @method module:skyring/lib/server#load
 * @return {module:skyring/lib/server}
 **/
load() {
if( this.loaded ) return this;

const routes = require('./api')
Expand All @@ -38,6 +65,15 @@ class Server extends http.Server {
return this;
}

/**
 * Joins the node to the configured ring and starts the http server
 * @method module:skyring/lib/server#listen
 * @param {Number} port Port number to listen on
 * @param {String} [host=localhost] host or ip address to listen on
* @param {Number} [backlog]
* @param {Function} [callback] Callback function to call when the server is running
 * @return {module:skyring/lib/server}
 **/
listen(port, host, backlog, callback) {
this._node.join(null, (err) => {
if (err) return callback(err)
Expand All @@ -64,6 +100,12 @@ class Server extends http.Server {
return this;
}

/**
 * Removes a server from the ring, closes the http server and redistributes
* any pending timers
 * @method module:skyring/lib/server#close
 * @param {Function} callback A callback to be called when the server is completely shut down
 **/
close( cb ){

super.close(()=>{
Expand Down

0 comments on commit 242e359

Please sign in to comment.