Constructor
new Server()
- Source:
Example
import * as soundworks from 'soundworks/server';
import MyExperience from './MyExperience';
soundworks.server.init(config);
const myExperience = new MyExperience();
soundworks.server.start();
Members
config
- Source:
Configuration informations. Defaults to:
{
env: {
type: 'development',
port: 8000,
subfolder: '',
useHttps: false,
},
app: {
name: 'soundworks',
},
}
httpServer
- Source:
Http(s) server instance. The node http
or https
module instance
(cf. https://nodejs.org/api/http.html)
httpsInfos
- Source:
If https is required, will contain informations about the certificates (self-signed, validity dates, etc.)
pluginManager :server.PluginManager
- Source:
- See:
The server.PluginManager instance.
Type:
router
- Source:
Router. Internally use polka. (cf. https://github.com/lukeed/polka)
sockets :server.Sockets
- Source:
- See:
The server.Sockets instance. A small wrapper around
ws
server.
Type:
stateManager :server.SharedStateManagerServer
- Source:
- See:
The server.SharedStateManagerServer instance.
Type:
templateDirectory
- Source:
Path to the directory containing the templates.
Any filename corresponding to a registered browser client type will be used
in priority, if not present fallback to default
, i.e ${clientType}.tmpl
fallbacks to default.tmpl
. Template files should have the .tmpl
extension.
templateEngine :Object
- Source:
Template engine that should implement a compile
method.
Type:
- Object
Methods
(async) init(config, clientConfigFunction)
- Source:
Method to be called before start
in the initialization lifecycle of the
soundworks server.
Example
// defaults to
await server.init(
{
env: {
type: 'development',
port: 8000,
subpath: '',
useHttps: false,
},
app: {
name: 'soundworks',
author: 'someone'
}
},
(clientType, serverConfig, httpRequest) => {
return { clientType, ...serverConfig };
}
);
Parameters:
Name | Type | Description | |||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
config |
Object |
Properties
|
|||||||||||||||||||||||||||||||||||
clientConfigFunction |
function | function that filters / defines the configuration object that will be sent to a connecting client. |
(async) start()
- Source:
Method to be called when init
step is done in the initialization
lifecycle of the soundworks server. Basically initialize plugins,
define the routing and start the http-server.