Hub server of SUGOS
SUGO-Hub works as a hub to connect SUGO-Actors and SUGO-Callers.
Table of Contents
Requirements
Installation
$ npm install sugo-hub --save
Usage
#!/usr/bin/env node /** * This is an example to setup hub server */ 'use strict' const sugoHub = { // Start sugo-hub server let hub = await hub console}
By default, SUGOS-Cloud provides WebSocket interfaces with following URLs:
URL | Description |
---|---|
/actors |
WebSocket namespace for [SUGO-Actors][sugo_actor_url] |
/callers |
WebSocket namespace for [SUGO-Callers][sugo_caller_url] |
/observers |
WebSocket namespace for [SUGO-Observers][sugo_observer_url] |
For more detail, see API Guide
Advanced Usage
SUGO cloud also provide bunch of options for building more complex applications.
Using Redis Server
By default, SUGO-Hub save state to json files. This may cause performance slow down on production. It is recommended to setup redis server for storage.
#!/usr/bin/env node /** * This is an example to setup hub server with redis */ 'use strict' const sugoHub = { let hub = await hub console}
Define HTTP Endpoints
SUGO-Hub uses Koa as http framework. You can define custom koa handlers on endpoints
field.
#!/usr/bin/env node /** * This is an example to setup hub server with endpoints */ 'use strict' const sugoHub = { let hub = await hub console}
Define HTTP Middlewares
For cross-endpoint handling, add koa middleware function to middlewares
field.
Note that static middlewares are provided as build-in middleware and you can serve static files by just setting directory names to static
field.
#!/usr/bin/env node /** * This is an example to setup hub server with middlewares */ 'use strict' const sugoHub = { let hub = await hub console}
Use Authentication
By providing authenticate
filed, you can authenticate sockets connecting.
#!/usr/bin/env node /** * This is an example to setup hub server with aut */ 'use strict' const sugoHub = { let hub = await hub console}
Register Local Actors
If you want to use actors on the same environment with hub, pass actors instances to localActors
option of hub.
#!/usr/bin/env node /** * This is an example to setup hub server with local actors */ 'use strict' const sugoHub = const sugoActor = { let hub = // Local actors automatically connect to the hub when it start listening await hub console}
License
This software is released under the Apache-2.0 License.