Skip to content

Commit

Permalink
Making the configuration Object optional, adding a CHANGELOG, updatin…
Browse files Browse the repository at this point in the history
…g `config.json` such that it doesn't inherit the "sample" routes

Updating README

Updating README
  • Loading branch information
avoidwork committed Aug 2, 2014
1 parent 4cb2300 commit 92b05f9
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 41 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Change Log

## 0.0.2
- Initial implementation of routing via external module

## 0.0.1
- Empty module, reserving the name
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,22 @@ Creating an API with Tensō is as simple as three statements.
```javascript
"use strict";

var tenso = require( "tenso" ),
config = require( __dirname + "/config.json" ),
app = tenso( config );
var tenso = require( "tenso" ),
app = tenso( {routes: "routes.js"} );
```

## Creating Routes
Routes are loaded as a module, affording a very customizable API server. The following example will return an empty `Array` at `/`, a `String` at `/reports/tps`, & a random number at `/random`.
Routes are loaded as a module, with each HTTP method as an export, affording a very customizable API server. The following example will create GET routes that will return an empty `Array` at `/`, an `Error` at `/reports/tps`, & a random number at `/random`.

```javascript
var random = require( "keigai" ).util.number.random,
prepare = require( "./lib/tenso" ).prepare;
prepare = require( "tenso" ).prepare;

module.exports.get = {
"/": [],
"/reports/tps": "TPS Cover Sheet not attached",
"/reports/tps": function ( req, res ) {
this.respond( req, res, prepare( null, new Error( "TPS Cover Sheet not attached" ), 785 ), 785 );
},
"/random": function ( req, res ) {
this.respond( req, res, prepare( random() ) );
}
Expand All @@ -49,3 +50,7 @@ This is a sample configuration for Tensō, without authentication or SSL. This w
}
}
```

## License
Copyright (c) 2014 Jason Mulligan
Licensed under the BSD-3 license.
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"hostname": "localhost",
"pageSize": 5,
"port": 8000,
"routes": "routes.js",
"routes": null,
"log": {
"dtrace": false,
"syslog": false
Expand Down
10 changes: 5 additions & 5 deletions doc/global.html
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="tenso.js.html">tenso.js</a>, <a href="tenso.js.html#sunlight-1-line-31">line 31</a>
<a href="tenso.js.html">tenso.js</a>, <a href="tenso.js.html#sunlight-1-line-34">line 34</a>
</li></ul></dd>


Expand Down Expand Up @@ -349,7 +349,7 @@ <h4 class="name" id="error"><span class="type-signature"></span>error<span class

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="tenso.js.html">tenso.js</a>, <a href="tenso.js.html#sunlight-1-line-72">line 72</a>
<a href="tenso.js.html">tenso.js</a>, <a href="tenso.js.html#sunlight-1-line-75">line 75</a>
</li></ul></dd>


Expand Down Expand Up @@ -441,7 +441,7 @@ <h4 class="name" id="factory"><span class="type-signature"></span>factory<span c

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="tenso.js.html">tenso.js</a>, <a href="tenso.js.html#sunlight-1-line-82">line 82</a>
<a href="tenso.js.html">tenso.js</a>, <a href="tenso.js.html#sunlight-1-line-85">line 85</a>
</li></ul></dd>


Expand Down Expand Up @@ -628,7 +628,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="tenso.js.html">tenso.js</a>, <a href="tenso.js.html#sunlight-1-line-109">line 109</a>
<a href="tenso.js.html">tenso.js</a>, <a href="tenso.js.html#sunlight-1-line-113">line 113</a>
</li></ul></dd>


Expand Down Expand Up @@ -702,7 +702,7 @@ <h5>Returns:</h5>

<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a>
on Fri Aug 01 2014 23:54:57 GMT-0400 (EDT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
on Sat Aug 02 2014 00:06:36 GMT-0400 (EDT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
</span>
</footer>
</div>
Expand Down
20 changes: 18 additions & 2 deletions doc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,30 @@ <h2>Example</h2>
<h2>Creating Routes</h2>
<p>Routes are loaded as a module, affording a very customizable API server. The following example will return an empty <code>Array</code> at <code>/</code>, a <code>String</code> at <code>/reports/tps</code>, &amp; a random number at <code>/random</code>.</p>
<pre><code class="lang-javascript">var random = require( &quot;keigai&quot; ).util.number.random,
prepare = require( &quot;tenso&quot; ).prepare;
prepare = require( &quot;./lib/tenso&quot; ).prepare;

module.exports.get = {
&quot;/&quot;: [],
&quot;/reports/tps&quot;: &quot;TPS Cover Sheet not attached&quot;,
&quot;/random&quot;: function ( req, res ) {
this.respond( req, res, prepare( random() ) );
}
}</code></pre>
<h2>Configuration</h2>
<p>This is a sample configuration for Tensō, without authentication or SSL. This would be ideal for development, but not production! Enabling is as easy as providing file paths for the two keys.</p>
<pre><code class="lang-json">{
&quot;hostname&quot;: &quot;localhost&quot;,
&quot;pageSize&quot;: 5,
&quot;port&quot;: 8000,
&quot;routes&quot;: &quot;routes.js&quot;,
&quot;log&quot;: {
&quot;dtrace&quot;: false,
&quot;syslog&quot;: false
},
&quot;ssl&quot;: {
&quot;key&quot;: null,
&quot;cert&quot;: null
}
}</code></pre></article>
</section>

Expand All @@ -141,7 +157,7 @@ <h2>Creating Routes</h2>

<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a>
on Fri Aug 01 2014 23:54:57 GMT-0400 (EDT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
on Sat Aug 02 2014 00:06:36 GMT-0400 (EDT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
</span>
</footer>
</div>
Expand Down
4 changes: 2 additions & 2 deletions doc/module-tenso.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ <h2>


<dt class="tag-version">Version:</dt>
<dd class="tag-version"><ul class="dummy"><li>0.0.1</li></ul></dd>
<dd class="tag-version"><ul class="dummy"><li>0.0.2</li></ul></dd>



Expand Down Expand Up @@ -186,7 +186,7 @@ <h2>

<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a>
on Fri Aug 01 2014 23:54:57 GMT-0400 (EDT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
on Sat Aug 02 2014 00:06:36 GMT-0400 (EDT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
</span>
</footer>
</div>
Expand Down
2 changes: 1 addition & 1 deletion doc/modules.list.html
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ <h2>

<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a>
on Fri Aug 01 2014 23:54:57 GMT-0400 (EDT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
on Sat Aug 02 2014 00:06:36 GMT-0400 (EDT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
</span>
</footer>
</div>
Expand Down
18 changes: 11 additions & 7 deletions doc/tenso.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,19 @@ <h1 class="page-title">Source: tenso.js</h1>
* @license BSD-3 &lt;https://raw.github.com/avoidwork/tenso/master/LICENSE>
* @link http://avoidwork.github.io/tenso
* @module tenso
* @version 0.0.1
* @version 0.0.2
*/
( function () {
"use strict";

var TurtleIO = require( "turtle.io" ),
SERVER = "tenso/0.0.1",
SERVER = "tenso/0.0.2",
CONFIG = require( __dirname + "/../config.json" ),
keigai = require( "keigai" ),
util = keigai.util,
iterate = util.iterate;
clone = util.clone,
iterate = util.iterate,
merge = util.merge;

/**
* Tenso
Expand All @@ -106,7 +109,7 @@ <h1 class="page-title">Source: tenso.js</h1>
function Tenso () {
this.messages = {};
this.server = new TurtleIO();
this.version = "0.0.1";
this.version = "0.0.2";
}

/**
Expand Down Expand Up @@ -166,9 +169,10 @@ <h1 class="page-title">Source: tenso.js</h1>
* @method factory
* @return {Object} Tenso instance
*/
function factory ( config ) {
var HOSTNAME = config.hostname || "localhost",
function factory ( arg ) {
var HOSTNAME = arg ? arg.hostname || "localhost" : "localhost",
vhosts = {},
config = arg ? merge( clone( CONFIG, true ), arg ) : CONFIG,
instance;

if ( !config.port ) {
Expand Down Expand Up @@ -232,7 +236,7 @@ <h1 class="page-title">Source: tenso.js</h1>

<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a>
on Fri Aug 01 2014 23:54:57 GMT-0400 (EDT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
on Sat Aug 02 2014 00:06:36 GMT-0400 (EDT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
</span>
</footer>
</div>
Expand Down
16 changes: 10 additions & 6 deletions lib/tenso.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
* @license BSD-3 <https://raw.github.com/avoidwork/tenso/master/LICENSE>
* @link http://avoidwork.github.io/tenso
* @module tenso
* @version 0.0.1
* @version 0.0.2
*/
( function () {
"use strict";

var TurtleIO = require( "turtle.io" ),
SERVER = "tenso/0.0.1",
SERVER = "tenso/0.0.2",
CONFIG = require( __dirname + "/../config.json" ),
keigai = require( "keigai" ),
util = keigai.util,
iterate = util.iterate;
clone = util.clone,
iterate = util.iterate,
merge = util.merge;

/**
* Tenso
Expand All @@ -25,7 +28,7 @@ var TurtleIO = require( "turtle.io" ),
function Tenso () {
this.messages = {};
this.server = new TurtleIO();
this.version = "0.0.1";
this.version = "0.0.2";
}

/**
Expand Down Expand Up @@ -85,9 +88,10 @@ function error ( server, req, res, status, err ) {
* @method factory
* @return {Object} Tenso instance
*/
function factory ( config ) {
var HOSTNAME = config.hostname || "localhost",
function factory ( arg ) {
var HOSTNAME = arg ? arg.hostname || "localhost" : "localhost",
vhosts = {},
config = arg ? merge( clone( CONFIG, true ), arg ) : CONFIG,
instance;

if ( !config.port ) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tenso",
"description": "Tensō is a REST framework for node.js, designed to simplify the implementation of APIs.",
"version": "0.0.1",
"version": "0.0.2",
"homepage": "http://avoidwork.github.io/tenso",
"author": {
"name": "Jason Mulligan",
Expand Down
4 changes: 3 additions & 1 deletion routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ var random = require( "keigai" ).util.number.random,

module.exports.get = {
"/": [],
"/reports/tps": "TPS Cover Sheet not attached",
"/reports/tps": function ( req, res ) {
this.respond( req, res, prepare( null, "TPS Cover Sheet not attached", 785 ), 785 );
},
"/random": function ( req, res ) {
this.respond( req, res, prepare( random() ) );
}
Expand Down
7 changes: 2 additions & 5 deletions sample.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
"use strict";

var tenso = require( "./lib/tenso" ),
config = require( __dirname + "/config.json" ),
app;

app = tenso(config);
var tenso = require( "./lib/tenso" ),
app = tenso( {routes: "routes.js"} );
8 changes: 5 additions & 3 deletions src/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
* Tenso factory
*
* @method factory
* @return {Object} Tenso instance
* @param {Object} arg [Optional] Configuration
* @return {Object} Tenso instance
*/
function factory ( config ) {
var HOSTNAME = config.hostname || "localhost",
function factory ( arg ) {
var HOSTNAME = arg ? arg.hostname || "localhost" : "localhost",
vhosts = {},
config = arg ? merge( clone( CONFIG, true ), arg ) : CONFIG,
instance;

if ( !config.port ) {
Expand Down
5 changes: 4 additions & 1 deletion src/intro.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

var TurtleIO = require( "turtle.io" ),
SERVER = "tenso/{{VERSION}}",
CONFIG = require( __dirname + "/../config.json" ),
keigai = require( "keigai" ),
util = keigai.util,
iterate = util.iterate;
clone = util.clone,
iterate = util.iterate,
merge = util.merge;

0 comments on commit 92b05f9

Please sign in to comment.