forerunnerdb
Version:
A NoSQL document store database for browsers and Node.js.
2,008 lines (520 loc) • 27.4 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Class: NodeApiServer</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Class: NodeApiServer</h1>
<section>
<header>
<h2>NodeApiServer</h2>
</header>
<article>
<div class="container-overview">
<h4 class="name" id="NodeApiServer"><span class="type-signature"></span>new NodeApiServer<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
The NodeApiServer class.
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="NodeApiServer.js.html">NodeApiServer.js</a>, <a href="NodeApiServer.js.html#line34">line 34</a>
</li></ul></dd>
</dl>
</div>
<h3 class="subsection-title">Methods</h3>
<ul><li><a href="#access"><span class="type-signature">(static) </span>access<span class="signature">(dbName, objType, objName, methodName, checkFunction)</span><span class="type-signature"> → {*}</span></a></li><li><a href="#express"><span class="type-signature"></span>express<span class="signature">()</span><span class="type-signature"> → {*|exports|module.exports}</span></a></li><li><a href="#handleRequest"><span class="type-signature"></span>handleRequest<span class="signature">(req, res)</span><span class="type-signature"></span></a></li><li><a href="#handleSyncRequest"><span class="type-signature"></span>handleSyncRequest<span class="signature">(req, res)</span><span class="type-signature"></span></a></li><li><a href="#hasPermission"><span class="type-signature"></span>hasPermission<span class="signature">(dbName, objType, objName, methodName, req, callback)</span><span class="type-signature"> → {*}</span></a></li><li><a href="#init"><span class="type-signature"></span>init<span class="signature">(core)</span><span class="type-signature"></span></a></li><li><a href="#sendToAll"><span class="type-signature"></span>sendToAll<span class="signature">(io, eventName, data)</span><span class="type-signature"></span></a></li><li><a href="#sendToClient"><span class="type-signature"></span>sendToClient<span class="signature">(res, messageId, eventName, stringifiedData)</span><span class="type-signature"></span></a></li><li><a href="#serverApp"><span class="type-signature"></span>serverApp<span class="signature">()</span><span class="type-signature"> → {*}</span></a></li><li><a href="#start"><span class="type-signature"></span>start<span class="signature">(host, port, options, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {<a href="NodeApiServer.html">NodeApiServer</a>}</span></a></li><li><a href="#stop"><span class="type-signature"></span>stop<span class="signature">()</span><span class="type-signature"></span></a></li></ul>
<h4 class="name" id=".access"><span class="type-signature">(static) </span>access<span class="signature">(dbName, objType, objName, methodName, checkFunction)</span><span class="type-signature"> → {*}</span></h4>
<div class="description">
Defines an access rule for an object and HTTP method combination. When
access is requested via a REST call, the function provided will be
executed and the callback from that method will determine if the
access will be allowed or denied. Multiple access functions can
be provided for a single model and method allowing authentication
checks to be stacked.
This call also allows you to pass a wildcard "*" instead of the objType,
objName and methodName parameters which will match all items. This
allows you to set permissions globally.
If no access permissions are present ForerunnerDB will automatically
deny any request to the resource by default.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>dbName</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">The name of the database to set access rules for.</td>
</tr>
<tr>
<td class="name"><code>objType</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">The type of object that the name refers to
e.g. "collection", "view" etc. This effectively maps to a method name on
the Db class instance. If you can do db.collection() then you can use the
string "collection" since it maps to the db.collection() method. This means
you can also use this to map to custom classes as long as you register
an accessor method on the Db class.</td>
</tr>
<tr>
<td class="name"><code>objName</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">The object name to apply the access rule to.</td>
</tr>
<tr>
<td class="name"><code>methodName</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">The name of the HTTP method to apply the access
function to e.g. "GET", "POST", "PUT", "PATCH" etc.</td>
</tr>
<tr>
<td class="name"><code>checkFunction</code></td>
<td class="type">
<span class="param-type">function</span>
|
<span class="param-type">String</span>
</td>
<td class="description last">The function to call when an access
attempt is made against the collection. A callback method is passed to this
function which should be called after the function has finished
processing. If you do not need custom logic to allow or deny access you
can simply pass the string "allow" or "deny" instead of a function and
ForerunnerDB will handle the logic automatically.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="NodeApiServer.js.html">NodeApiServer.js</a>, <a href="NodeApiServer.js.html#line742">line 742</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">*</span>
</dd>
</dl>
<h4 class="name" id="express"><span class="type-signature"></span>express<span class="signature">()</span><span class="type-signature"> → {*|exports|module.exports}</span></h4>
<div class="description">
Gets the express library.
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="NodeApiServer.js.html">NodeApiServer.js</a>, <a href="NodeApiServer.js.html#line194">line 194</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">*</span>
|
<span class="param-type">exports</span>
|
<span class="param-type">module.exports</span>
</dd>
</dl>
<h4 class="name" id="handleRequest"><span class="type-signature"></span>handleRequest<span class="signature">(req, res)</span><span class="type-signature"></span></h4>
<div class="description">
Handles requests from clients to the endpoints the database exposes.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>req</code></td>
<td class="type">
</td>
<td class="description last"></td>
</tr>
<tr>
<td class="name"><code>res</code></td>
<td class="type">
</td>
<td class="description last"></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="NodeApiServer.js.html">NodeApiServer.js</a>, <a href="NodeApiServer.js.html#line316">line 316</a>
</li></ul></dd>
</dl>
<h4 class="name" id="handleSyncRequest"><span class="type-signature"></span>handleSyncRequest<span class="signature">(req, res)</span><span class="type-signature"></span></h4>
<div class="description">
Handles client requests to open an EventSource connection to our
server-sent events server.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>req</code></td>
<td class="type">
</td>
<td class="description last"></td>
</tr>
<tr>
<td class="name"><code>res</code></td>
<td class="type">
</td>
<td class="description last"></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="NodeApiServer.js.html">NodeApiServer.js</a>, <a href="NodeApiServer.js.html#line595">line 595</a>
</li></ul></dd>
</dl>
<h4 class="name" id="hasPermission"><span class="type-signature"></span>hasPermission<span class="signature">(dbName, objType, objName, methodName, req, callback)</span><span class="type-signature"> → {*}</span></h4>
<div class="description">
Checks for permission to access the specified object.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>dbName</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last"></td>
</tr>
<tr>
<td class="name"><code>objType</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last"></td>
</tr>
<tr>
<td class="name"><code>objName</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last"></td>
</tr>
<tr>
<td class="name"><code>methodName</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last"></td>
</tr>
<tr>
<td class="name"><code>req</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last"></td>
</tr>
<tr>
<td class="name"><code>callback</code></td>
<td class="type">
<span class="param-type">function</span>
</td>
<td class="description last"></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="NodeApiServer.js.html">NodeApiServer.js</a>, <a href="NodeApiServer.js.html#line722">line 722</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">*</span>
</dd>
</dl>
<h4 class="name" id="init"><span class="type-signature"></span>init<span class="signature">(core)</span><span class="type-signature"></span></h4>
<div class="description">
The init method that can be overridden or extended.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>core</code></td>
<td class="type">
<span class="param-type"><a href="Core.html">Core</a></span>
</td>
<td class="description last">The ForerunnerDB core instance.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="NodeApiServer.js.html">NodeApiServer.js</a>, <a href="NodeApiServer.js.html#line42">line 42</a>
</li></ul></dd>
</dl>
<h4 class="name" id="sendToAll"><span class="type-signature"></span>sendToAll<span class="signature">(io, eventName, data)</span><span class="type-signature"></span></h4>
<div class="description">
Sends server-sent-events message to all connected clients that are listening
to the changes in the IO that is passed.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>io</code></td>
<td class="type">
</td>
<td class="description last"></td>
</tr>
<tr>
<td class="name"><code>eventName</code></td>
<td class="type">
</td>
<td class="description last"></td>
</tr>
<tr>
<td class="name"><code>data</code></td>
<td class="type">
</td>
<td class="description last"></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="NodeApiServer.js.html">NodeApiServer.js</a>, <a href="NodeApiServer.js.html#line677">line 677</a>
</li></ul></dd>
</dl>
<h4 class="name" id="sendToClient"><span class="type-signature"></span>sendToClient<span class="signature">(res, messageId, eventName, stringifiedData)</span><span class="type-signature"></span></h4>
<div class="description">
Sends data to individual client.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>res</code></td>
<td class="type">
</td>
<td class="description last"></td>
</tr>
<tr>
<td class="name"><code>messageId</code></td>
<td class="type">
</td>
<td class="description last"></td>
</tr>
<tr>
<td class="name"><code>eventName</code></td>
<td class="type">
</td>
<td class="description last"></td>
</tr>
<tr>
<td class="name"><code>stringifiedData</code></td>
<td class="type">
</td>
<td class="description last">Data to send in already-stringified format.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="NodeApiServer.js.html">NodeApiServer.js</a>, <a href="NodeApiServer.js.html#line704">line 704</a>
</li></ul></dd>
</dl>
<h4 class="name" id="serverApp"><span class="type-signature"></span>serverApp<span class="signature">()</span><span class="type-signature"> → {*}</span></h4>
<div class="description">
Gets the express app (router).
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="NodeApiServer.js.html">NodeApiServer.js</a>, <a href="NodeApiServer.js.html#line186">line 186</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">*</span>
</dd>
</dl>
<h4 class="name" id="start"><span class="type-signature"></span>start<span class="signature">(host, port, options, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {<a href="NodeApiServer.html">NodeApiServer</a>}</span></h4>
<div class="description">
Starts the rest server listening for requests against the ip and
port number specified.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>host</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="attributes">
</td>
<td class="description last">The IP address to listen on, set to 0.0.0.0 to
listen on all interfaces.</td>
</tr>
<tr>
<td class="name"><code>port</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="attributes">
</td>
<td class="description last">The port to listen on.</td>
</tr>
<tr>
<td class="name"><code>options</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="attributes">
</td>
<td class="description last">An options object.</td>
</tr>
<tr>
<td class="name"><code>callback</code></td>
<td class="type">
<span class="param-type">function</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">The method to call when the server has
started (or failed to start).</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="NodeApiServer.js.html">NodeApiServer.js</a>, <a href="NodeApiServer.js.html#line89">line 89</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type"><a href="NodeApiServer.html">NodeApiServer</a></span>
</dd>
</dl>
<h4 class="name" id="stop"><span class="type-signature"></span>stop<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
Stops the server listener.
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="NodeApiServer.js.html">NodeApiServer.js</a>, <a href="NodeApiServer.js.html#line299">line 299</a>
</li></ul></dd>
</dl>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="ActiveBucket.html">ActiveBucket</a></li><li><a href="Angular.html">Angular</a></li><li><a href="AutoBind.html">AutoBind</a></li><li><a href="Collection.html">Collection</a></li><li><a href="CollectionGroup.html">CollectionGroup</a></li><li><a href="Condition.html">Condition</a></li><li><a href="Core.html">Core</a></li><li><a href="Db.html">Db</a></li><li><a href="Document.html">Document</a></li><li><a href="Grid.html">Grid</a></li><li><a href="Highchart.html">Highchart</a></li><li><a href="Index2d.html">Index2d</a></li><li><a href="IndexBinaryTree.html">IndexBinaryTree</a></li><li><a href="IndexHashMap.html">IndexHashMap</a></li><li><a href="Infinilist.html">Infinilist</a></li><li><a href="KeyValueStore.html">KeyValueStore</a></li><li><a href="Metrics.html">Metrics</a></li><li><a href="MyModule.html">MyModule</a></li><li><a href="NodeApiClient.html">NodeApiClient</a></li><li><a href="NodeApiServer.html">NodeApiServer</a></li><li><a href="NodeRAS.html">NodeRAS</a></li><li><a href="Odm.html">Odm</a></li><li><a href="OldView.html">OldView</a></li><li><a href="Operation.html">Operation</a></li><li><a href="Overload.html">Overload</a></li><li><a href="Overview.html">Overview</a></li><li><a href="Overview_init.html">init</a></li><li><a href="Path.html">Path</a></li><li><a href="Persist.html">Persist</a></li><li><a href="Procedure.html">Procedure</a></li><li><a href="ReactorIO.html">ReactorIO</a></li><li><a href="Section.html">Section</a></li><li><a href="Serialiser.html">Serialiser</a></li><li><a href="Shared.overload.html">overload</a></li><li><a href="View.html">View</a></li></ul><h3>Mixins</h3><ul><li><a href="ChainReactor.html">ChainReactor</a></li><li><a href="Common.html">Common</a></li><li><a href="Constants.html">Constants</a></li><li><a href="Events.html">Events</a></li><li><a href="Matching.html">Matching</a></li><li><a href="Shared.html">Shared</a></li><li><a href="Sorting.html">Sorting</a></li><li><a href="Tags.html">Tags</a></li><li><a href="Triggers.html">Triggers</a></li><li><a href="Updating.html">Updating</a></li></ul><h3><a href="global.html">Global</a></h3>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Thu Mar 01 2018 11:34:23 GMT+0000 (GMT)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>