isnode-mod-services
v0.1.9
Published
ISNode Services Module
Downloads
2
Readme
ISNode Services 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 Services module is responsible for loading all installed services and their respective controllers, and for providing an interface for the router to direct requests to the relevent controller.
Configuration
There is currently one attribute that is configurable within the application server's configuration file (config.json) - "allowShutdownFromControllers". If this is set to "true", then it makes the application server (system-wide) shutdown() method available from the "isnode" object that is passed to all of the controllers. If it is set to "false" then the controllers will not be able to access the shutdown() method and will not have any ability to terminate the application server (barring an exception).
"services": {
"allowShutdownFromControllers": false
}
Methods
search(searchObj)
Synchronous Function. Searches for an returns a controller based on serviec name(s), hostname and url (path)
Input Parameters:
- searchObj - (Object) Search Object. See example below
Returns: Returns a route object that includes the controller
SearchObj example
{
services: ["service1", "service2"],
hostname: "localhost",
url: "/web/users/1"
}
service(name)
Synchronous Function. Returns a service object, given a service name. Using this object you can navigate the service routes (including controllers), database models instantiated against the service and service configuration.
Input Parameters:
- name - (String) Name of the service to return.
Returns: Returns a service object
Example
var helloWorldService = isnode.module("services").service("hello-world");
service(name).cfg()
Synchronous Function. Fetches service configuration object
Input Parameters:
- name - (String) Name of the service
Returns: Service configuration object
Example
var serviceConfig = isnode.module("services").service("hello-world").cfg();
service(name).model.add(modelName, modelObj)
Synchronous Function. Adds a model against a service.
Input Parameters:
- name - (String) Name of the service
- modelName - (String) Name of the model to add
- modelObj - (Object) The model object to add
Returns: Returns true on successful addition of model to service
Example
// Assume "model" has already been defined
isnode.module("services").service("hello-world").model.add("test", model);
service(name).model.get(modelName)
Synchronous Function. Fetches a defined model from a service
Input Parameters:
- name - (String) Name of the service
- modelName - (String) Name of the model to fetch
Returns: Returns the model object
Example
// Assume "model" has already been defined
var model = isnode.module("services").service("hello-world").model.get("test");
service(name).url.get(path, options)
Synchronous Function. Takes a controller-relative path and returns application path (including base url)
Input Parameters:
- path - (String) Controller-relative path
- options - (Object) Child strings of "protocol", "port" and "full". Only need to set protocol and port if full is set as this will return an absolute URL. If full is not set or is set to false it will return the relative path
Returns: Returns a URL (absolute or relative path depending on input)
Example
// Assume basePath is set to "/test/path"
var url = isnode.module("services").service("hello-world").url.get("/web/test");
console.log(url); // Should render "/test/path/web/test"