1.2.1 • Published 6 years ago

cubic-loader v1.2.1

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

cubic-loader

npm build dependencies

Usage

const loader = require('cubic-loader')
const Auth = require('cubic-auth')
const API = require('cubic-api')
const Core = require('cubic-core')

loader(options) // Generates a global `cubic` object

cubic.use(new Auth()) // Auth server required to authorize the core node to respond to API requests
cubic.use(new API())  // Web API serving requests from core node below
cubic.use(new Core()) // Core node handling all API endpoints

This will load an API and Core node to the global cubic object. The nodes can be accessed via cubic.nodes.api and cubic.nodes.core. Each node's final config (i.e. provided options merged with defaults) is accessible via cubic.config[node].

If we wish to use multiple API/Core nodes for different purposes, we can pass a group like { group: 'analytics' } to the node constructors, making nodes accessible via cubic.nodes.analytics.api and vice-versa for node configs.

Hooks

Hooks allow you to execute functions right before a certain node launches. Within the function, you'll have access to cubic.config[node] with all the options you've set in cubic.use().

Example

require('cubic-loader')()
const API = require('cubic-api')

const options = { ferret: 'tobi' }
const hookFn = () => console.log(cubic.config.api.ferret)

cubic.hook(API, hookFn) // Hooks function on provided node
cubic.use(new API(options)) // logs 'tobi', before node is loaded

The stack of hook functions will be saved in cubic.hooks[node].

Options

require('cubic-loader')({ key: value })
KeyValueDescription
environmentdevelopment/
environmentproduction/
logLevelinfoDefault log level. Logs limited information about the node status.
logLevelerrorError Log Level. Helpful for automated tests.
logLevelverboseVerbose log level. Includes Request Timestamps, Socket Connections, Config events, etc.
logLevelsillySilly log level. Includes internal information on which routes are being bound, diagnostics and lifecycle details.
throwErrorsfalseThrow errros while in production. console.error()'s them by default otherwise.

Configuration settings will be accessible via cubic.config.local. For configuration of individual nodes, check out their repositories below.

Available Nodes

RepositoryLinkDescription
cubic-apiRESTful API with WebSocket support which authorizes and distributes requests to core nodes.
cubic-coreResource Server for simple endpoint implementation to the API node.
cubic-authAuthentication Server for creating users and providing JSON Web Tokens to grant authorization on the API node.
cubic-uiView node for rendering web pages.

License

MIT

1.2.1

6 years ago

1.2.0

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago