Skip to content

Commit

Permalink
server: pass server args through to underlying http server
Browse files Browse the repository at this point in the history
infer the arguments so we don't have to pass null arguments to get a
callback
  • Loading branch information
esatterwhite committed Aug 27, 2017
1 parent a808d65 commit 18e7e48
Show file tree
Hide file tree
Showing 48 changed files with 107 additions and 68 deletions.
35 changes: 28 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,37 @@ DEBUG=skyring:* skyring run -p 3000 -s localhost:3456 -s localhost:3455
```


### Clone Skyring
### Using in your project

Alternatively to the CLI, you can clone and install the project manually
If you want to use the skyring directly, you can just require it and start it directly.
most of the available enviroment and cli arguments can be passed to the {@link module:skyring/lib/server|skyring constructor}.
If you don't pass anything to the construct the default values are {@link module:keef|loaded} from the appropriate sources

```bash
$ git clone https://github.com/esatterwhite/skyring.git
$ cd skyring
$ npm install
$ DEBUG=* node index.js
```javascript
// index.js
const Skyring = require('skyring')
const server = new Skyring()

function onSignal() {
server.close(()=>{
console.log('shutting down');
});
}

server.load().listen(3000, (err) => {
if (err) throw err
console.log('skyring listening at %s', 'http://0.0.0.0:3000')
})

process.once('SIGINT', onSignal);
process.once('SIGTERM', onSignal);
```

This can then be started as a single node cluster
```
$ DEBUG=* node . --channel:port=3455 --seeds='localhost:3455'
```

The default settings expect a minimum of 2 servers on port `3455` and `3456` respectively. Start each server in a different terminal session
```bash
# Seed node 1
Expand Down
4 changes: 2 additions & 2 deletions docs/api/api_project.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
define({
"name": "skyring",
"version": "4.3.0",
"version": "4.4.1",
"description": "Distributed timers as a service",
"sampleUrl": false,
"apidoc": "0.2.0",
"generator": {
"name": "apidoc",
"time": "2017-07-03T12:25:57.507Z",
"time": "2017-08-27T17:08:21.468Z",
"url": "http://apidocjs.com",
"version": "0.16.1"
}
Expand Down
4 changes: 2 additions & 2 deletions docs/api/api_project.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "skyring",
"version": "4.3.0",
"version": "4.4.1",
"description": "Distributed timers as a service",
"sampleUrl": false,
"apidoc": "0.2.0",
"generator": {
"name": "apidoc",
"time": "2017-07-03T12:25:57.507Z",
"time": "2017-08-27T17:08:21.468Z",
"url": "http://apidocjs.com",
"version": "0.16.1"
}
Expand Down
2 changes: 1 addition & 1 deletion docs/classes.list.html
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a>

on 2017-07-03T07:25:57-05:00
on 2017-08-27T12:08:20-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
30 changes: 23 additions & 7 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,27 @@ <h1>Install</h1><pre class="prettyprint source"><code>npm install -s skyring</co
PONG</code></pre><h3>Skyring CLI</h3><p>If you intend to run skyring as is, it may be preferable to use the included binary over cloning the project.</p>
<pre class="prettyprint source"><code>npm install -g skyring

DEBUG=skyring:* skyring run -p 3000 -s localhost:3456 -s localhost:3455</code></pre><h3>Clone Skyring</h3><p>Alternatively to the CLI, you can clone and install the project manually</p>
<pre class="prettyprint source lang-bash"><code>$ git clone https://github.com/esatterwhite/skyring.git
$ cd skyring
$ npm install
$ DEBUG=* node index.js</code></pre><p>The default settings expect a minimum of 2 servers on port <code>3455</code> and <code>3456</code> respectively. Start each server in a different terminal session</p>
DEBUG=skyring:* skyring run -p 3000 -s localhost:3456 -s localhost:3455</code></pre><h3>Using in your project</h3><p>If you want to use the skyring directly, you can just require it and start it directly.
most of the available enviroment and cli arguments can be passed to the <a href="module-skyring_lib_server.html">skyring constructor</a>.
If you don't pass anything to the construct the default values are <a href="module-keef.html">loaded</a> from the appropriate sources</p>
<pre class="prettyprint source lang-javascript"><code>// index.js
const Skyring = require('skyring')
const server = new Skyring()

function onSignal() {
server.close(()=>{
console.log('shutting down');
});
}

server.load().listen(3000, (err) => {
if (err) throw err
console.log('skyring listening at %s', 'http://0.0.0.0:3000')
})

process.once('SIGINT', onSignal);
process.once('SIGTERM', onSignal);</code></pre><p>This can then be started as a single node cluster</p>
<pre class="prettyprint source"><code>$ DEBUG=* node . --channel:port=3455 --seeds='localhost:3455'</code></pre><p>The default settings expect a minimum of 2 servers on port <code>3455</code> and <code>3456</code> respectively. Start each server in a different terminal session</p>
<pre class="prettyprint source lang-bash"><code># Seed node 1
$ DEBUG=skyring:* node index.js --channel:port=3455 -p 3000</code></pre><pre class="prettyprint source lang-bash"><code># Seed node 2
$ DEBUG=skyring:* node index.js --channel:port=3456 -p 3001</code></pre><p>If all goes well you should see a message like this</p>
Expand Down Expand Up @@ -158,7 +174,7 @@ <h2>Create a timer</h2><h5><strong>POST <code>/timer</code></strong></h5><p><str
Connection: keep-alive
Content-Length: 0</code></pre><h2>Cancel A Timer</h2><h5><strong>DELETE <code>/timer/:id</code></strong></h5><p><strong>Request</strong></p>
<pre class="prettyprint source lang-bash"><code>curl -i -XDELETE http://localhost:8080/timer/4adb026b-6ef3-44a8-af16-4d6be0343ecf</code></pre><p><strong>Response Headers</strong></p>
<pre class="prettyprint source"><code>HTTP/1.1 202 Accepted
<pre class="prettyprint source lang-http"><code>HTTP/1.1 202 Accepted
Date: Fri, 23 Dec 2016 00:22:12 GMT
Connection: keep-alive
Content-Length: 0</code></pre><h1>Crash Recovery</h1><p>Each Skyring node uses an internal <a href="https://www.npmjs.com/package/levelup">levelup</a> instance to record timers that it owns.
Expand Down Expand Up @@ -242,7 +258,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a>

on 2017-07-03T07:25:57-05:00
on 2017-08-27T12:08:20-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
4 changes: 2 additions & 2 deletions docs/index.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ <h1 class="page-title">Source: index.js</h1>

const server = new Server();

server.load().listen(conf.get('PORT'),null, null, (err) => {
server.load().listen(conf.get('PORT'), (err) => {
if(err) {
process.exitCode = 1;
console.error(err);
Expand Down Expand Up @@ -195,7 +195,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a>

on 2017-07-03T07:25:57-05:00
on 2017-08-27T12:08:20-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/lib_json.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a>

on 2017-07-03T07:25:57-05:00
on 2017-08-27T12:08:20-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/lib_nats.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a>

on 2017-07-03T07:25:57-05:00
on 2017-08-27T12:08:20-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
9 changes: 5 additions & 4 deletions docs/lib_server_index.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,20 +217,21 @@ <h1 class="page-title">Source: lib/server/index.js</h1>
* @param {Function} [callback] Callback function to call when the server is running
* @return {module:skyring/lib/server}
**/
listen(port, host, backlog, callback) {
listen(port, ...args) {
const callback = args[args.length - 1]
debug('seed nodes', this.options.seeds);
this._node.join(this.options.seeds, (err) => {
if (err) {
console.error(err);
return callback &amp;&amp; callback(err);
return typeof callback === 'function' ? callback(err) : null;
}
this._node.handle(( req, res ) => {
this._router.handle( req, res );
});
this._timers.watch(`skyring:${this._group}`, (err, data) => {
this.proxy(data);
});
super.listen(port, host, backlog, callback);
super.listen(port, ...args);
});
return this;
}
Expand Down Expand Up @@ -316,7 +317,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a>

on 2017-07-03T07:25:57-05:00
on 2017-08-27T12:08:20-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/lib_server_mock.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a>

on 2017-07-03T07:25:57-05:00
on 2017-08-27T12:08:20-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/lib_server_node.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a>

on 2017-07-03T07:25:57-05:00
on 2017-08-27T12:08:20-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/lib_server_request.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a>

on 2017-07-03T07:25:57-05:00
on 2017-08-27T12:08:20-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/lib_server_response.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a>

on 2017-07-03T07:25:57-05:00
on 2017-08-27T12:08:20-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/lib_server_route.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a>

on 2017-07-03T07:25:57-05:00
on 2017-08-27T12:08:20-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/lib_server_router.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a>

on 2017-07-03T07:25:57-05:00
on 2017-08-27T12:08:20-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/lib_timer.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a>

on 2017-07-03T07:25:57-05:00
on 2017-08-27T12:08:20-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/lib_transports_callback.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a>

on 2017-07-03T07:25:57-05:00
on 2017-08-27T12:08:20-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/lib_transports_http.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a>

on 2017-07-03T07:25:57-05:00
on 2017-08-27T12:08:20-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/lib_transports_index.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a>

on 2017-07-03T07:25:57-05:00
on 2017-08-27T12:08:20-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/module-keef.html
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a>

on 2017-07-03T07:25:57-05:00
on 2017-08-27T12:08:20-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/module-skyring.html
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a>

on 2017-07-03T07:25:57-05:00
on 2017-08-27T12:08:20-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/module-skyring_conf.html
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a>

on 2017-07-03T07:25:57-05:00
on 2017-08-27T12:08:20-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/module-skyring_lib_json.html
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a>

on 2017-07-03T07:25:57-05:00
on 2017-08-27T12:08:20-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/module-skyring_lib_nats.html
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a>

on 2017-07-03T07:25:57-05:00
on 2017-08-27T12:08:21-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/module-skyring_lib_server.html
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a>

on 2017-07-03T07:25:57-05:00
on 2017-08-27T12:08:21-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/module-skyring_lib_server_mock.Request.html
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a>

on 2017-07-03T07:25:57-05:00
on 2017-08-27T12:08:21-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/module-skyring_lib_server_mock.Response.html
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a>

on 2017-07-03T07:25:57-05:00
on 2017-08-27T12:08:21-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/module-skyring_lib_server_mock.html
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a>

on 2017-07-03T07:25:57-05:00
on 2017-08-27T12:08:21-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/module-skyring_lib_server_node.html
Original file line number Diff line number Diff line change
Expand Up @@ -1716,7 +1716,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a>

on 2017-07-03T07:25:57-05:00
on 2017-08-27T12:08:21-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/module-skyring_lib_server_request.html
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a>

on 2017-07-03T07:25:57-05:00
on 2017-08-27T12:08:21-05:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
Loading

0 comments on commit 18e7e48

Please sign in to comment.