isnode-mod-router
v0.1.6
Published
ISNode Router Module
Downloads
2
Readme
ISNode Router Module
Introduction
This is just a module for the ISNode Framework. To learn how to use the framework, we strongly suggest obtaining a copy of the Hello World example.
The router module is responsible for creating, managing and utilizing routers. Routers are defined within the system configuration file and are responsible for passing requests from interfaces through to service controllers.
System Configuration
Below is an example configuration for the router module within the system configuration file (config.json). It defines a single router instance that routes messages from all interfaces to all services. You can also define individual interfaces and services by name within the array instead of the "select all" (*) symbol. This module also supports the definition of multiple routers - and thus makes for a very configurable framework.
"router": {
"instances": {
"RouterOne": {
"interfaces": ["*"],
"services": ["*"]
}
}
}
Methods
count()
Synchronous Function. Returns a count of the number of routers that have been instantiated
Input Parameters:
N/A
Returns: (Integer) A count of the number of instantiated routers
Example
console.log(isnode.module("router").count()); // Prints "2" to the console if 2 routers have been instantiated
get(name)
Synchronous Function. Returns a router based on its name
Input Parameters:
- name - (Object) Name of the router
Returns: The router object
Example
var RouterOne = isnode.module("router").get("RouterOne");
router.incoming(message)
Event-Driven Function. Accepts an incoming message from an interface and routes it to the relevent service controller. Also opens a listener for a response event and routes it back to the interface when received.
Input Parameters:
- message - (Object) Message Object
Returns: N/A
Example
var message = {
"type": "http",
"interface": "http",
"msgId": "1234",
"state": "incoming",
"directional": "simplex",
"request": {
"path": "/",
"host": "localhost",
"port": 80,
"query": "name=john@age=21",
"headers": {},
"params": {},
"cookies": {},
"ip": "127.0.0.11",
"verb": "GET",
"secure": false,
"body": "",
}
}
var RouterOne = isnode.module("router").get("RouterOne");
RouterOne.incoming(message);
router.route(hostname, url)
Synchronous Function. Returns a route object that references service+controller, based on a hostname and url (path)
Input Parameters:
- hostname - (String) Hostname
- url - (String) URL Path
Returns: N/A
Example
var route = RouterOne.route("localhost", "/test");