Class: NodeApiServer

NodeApiServer

new NodeApiServer()

The NodeApiServer class.
Source:

Methods

(static) access(dbName, objType, objName, methodName, checkFunction) → {*}

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.
Parameters:
Name Type Description
dbName String The name of the database to set access rules for.
objType String 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.
objName String The object name to apply the access rule to.
methodName String The name of the HTTP method to apply the access function to e.g. "GET", "POST", "PUT", "PATCH" etc.
checkFunction function | String 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.
Source:
Returns:
Type
*

express() → {*|exports|module.exports}

Gets the express library.
Source:
Returns:
Type
* | exports | module.exports

handleRequest(req, res)

Handles requests from clients to the endpoints the database exposes.
Parameters:
Name Type Description
req
res
Source:

handleSyncRequest(req, res)

Handles client requests to open an EventSource connection to our server-sent events server.
Parameters:
Name Type Description
req
res
Source:

hasPermission(dbName, objType, objName, methodName, req, callback) → {*}

Checks for permission to access the specified object.
Parameters:
Name Type Description
dbName String
objType String
objName String
methodName String
req Object
callback function
Source:
Returns:
Type
*

init(core)

The init method that can be overridden or extended.
Parameters:
Name Type Description
core Core The ForerunnerDB core instance.
Source:

sendToAll(io, eventName, data)

Sends server-sent-events message to all connected clients that are listening to the changes in the IO that is passed.
Parameters:
Name Type Description
io
eventName
data
Source:

sendToClient(res, messageId, eventName, stringifiedData)

Sends data to individual client.
Parameters:
Name Type Description
res
messageId
eventName
stringifiedData Data to send in already-stringified format.
Source:

serverApp() → {*}

Gets the express app (router).
Source:
Returns:
Type
*

start(host, port, options, callbackopt) → {NodeApiServer}

Starts the rest server listening for requests against the ip and port number specified.
Parameters:
Name Type Attributes Description
host String The IP address to listen on, set to 0.0.0.0 to listen on all interfaces.
port String The port to listen on.
options Object An options object.
callback function <optional>
The method to call when the server has started (or failed to start).
Source:
Returns:
Type
NodeApiServer

stop()

Stops the server listener.
Source: