Skip to content

Latest commit

 

History

History
423 lines (341 loc) · 12.7 KB

modulemanager.md

File metadata and controls

423 lines (341 loc) · 12.7 KB
description
Represents the hyron, containing the basic methods for running the application

ModuleManager

{% hint style="warning" %} Note: this class is no longer used, instead you should use the @hyron/cli package to work with hyron more easily, and better support later {% endhint %}

class ModuleManager

Details

class ModuleManager

Used to register & management elements in project, like instance, service, plugins, addons. It is base of Hyron Framework

function build

Used to run the application with a json build file. It supported by AppLoader

★ params

static build(path) : void
name type description
path string referenced to JSON build file from root

function getInstance

Used to create a new instance, that can be used to create difference server. default server will listen on http://localhost:3000

★ Params

static gtInstance() : ModuleManager

(empty)

static getInstance(baseUrl) : ModuleManager
name type description
baseUrl string a url specified where the server will run on
static getInstance(port, host?, prefix?, protocol?): ModuleManager
name type description
post number a free port. if port is 0, server will listen on random available port. default is 3000
host string host name or IP address of current machine. Default is localhost
prefix string a path to separate your routers, used to group routers into an instance. Default is empty
protocol string a protocol for this instance. default is http
static getInstance (serverConfig) : ModuleManager
name type description
serverConfig object object contain server config. include : protocol, host, port, prefix

Return

type description
ModuleManager Current instance, that could be used to do something else

function getInstanceContainer

Used to get all app instance created. This feature usually used by addons and expanded module to handle a central problems

★ Params

static getInstanceContainer() : Array<ModuleManager>

(empty)

★ Return

type description
Array<ModuleManager> a list of instances represent by baseUrl and instances

function setting

Used by modules from app, to make app more scalable & easy to management. setting will be overwrite onto setting value loaded by appcfg.yaml. Except lock field.

Params

setting(config) : void
name type description
config object a description object contain config for this instance modules
config.environment string dev or product. if it is dev, program should collect problem, else it should to optimized for performance
config.timeout number expert timeout for router connection. default is 60s
config.style string style of uri path. Hyron support for 4 style, include : camel, snake, lisp, lower. default is lisp
config.secret string a private key that used to for encode a sensitive content

function getConfig

Retrieve config value for a key by name

Params

static getConfig(name, defaultValue?) : any
name type description
name string config value or null if config not found. It allow support to browse child values by. example : mailer.auth.email
defaultValue any value if do not found config by abort key

Return

type description
any config data. described in appcfg file

function enableAddons

Used to register addons for this instance. A addons could have access to all the resources provided in this class via this args. It used to bring more power for Hyron to handle advanced problems. se to expand hyron or run cron jobs

Params

enableAddons ( paths ) : void
nam type description
paths object<name,path>

list of linked addons referenced by path from root

  • name (string) : name of addons
  • path (string) : link to addons hander from root
\`\`\`javascript enableAddons\(packs\) : void \`\`\`
name type description
packs object<name,pack>

List of packaged ađons

  • name (string) : name of addons
  • pack (ServicesMeta | UnofficialService) : handle package that used by hyron to register router
### function enableGlobalAddons

Used to register global addons that have been called on each instance when it created

Params

enableGlobalAddons(paths) : void
name type description
paths object<name,path>

list of linked addons referenced by path from root

  • name (string) : name of addons
  • path (string) : link to addons hander from root
\`\`\`javascript enableGlobalAddons\(packs\) : void \`\`\`
name type description
packs object<name,pack>

List of packaged plugins

  • name (string) : name of addons
  • pack (AddonsMeta) : handle package that used by hyron to register addon
### function enablePlugins

This method used to register plugins with name provided. After plugins declared, it can be used inside your app by name

The name of the plugins needs to be consistent and easy to remember, so that it can be used easily

Params

enablePlugins(paths) : void
name type description
paths object<name,path>

list of linked plugins referenced by path from root

  • name (string) : name of addons
  • path (string) : link to addons hander from root
\`\`\`javascript enablePlugins\(packs\) : void \`\`\`
name type description
packs object<name,pack>

list of packaged plugins

  • name (string) : name of addons
  • pack (PluginsMeta) : handle package that used by hyron to register plugin
### function enableService

Used to register routers for this instance. Service is a Object contain set of function that serve for a specific business purpose. To distinguish whether a package is a Hyron service or not based on the requestConfig method

★ Params

enableServices(paths) : void
name type description
paths object<name,path>

list of linked services referenced by path from root

  • name (string) : name of addons
  • path (string) : link to services package from root
\`\`\`javascript enableServices\(packs\) : void \`\`\`
name type description
handles object<name,pack>

list of packaged services

  • name (string) : name of addons
  • pack (HyronService | UnofficialService) : handle package that used by hyron to register router
### function initServer

Used to custom server of this instance, and set it default listeners. By default, it called for the first time instance created with node http server.

Params

initServer(server) : void
name type description
server Server server to handle client request and response. default is http.Server

****

function setServer

This function could be used by addons to edit server for many instances

Params

static setServer(host, port, server) : void
name type description
host string host name of specified instance
port number port number of specified instance
server Server server to handle client request and response. default is http.Server

function startServer

Start this instance for listen client request

Params

static startServer(callback) : void
name type description
callback function event that will be called when server started