Command-line utils for connecting to a UnityBase server
const argv = require('@unitybase/base').argv
// connect to server
let session = argv.establishConnectionFromCmdLineAttributes()
console.log('Session.uData:', session.uData, typeof session.uData, session.uData.lang)
let userLang = session.uData.lang
let conn = session.connection
// obtain domain information
const domainInfo = conn.getDomainInfo()
Classes
Members
# findCmdLineSwitch deprecated static
Use `options.switchIndex` instead.
# findCmdLineSwitchValue deprecated static
Use `options.switchValue` instead.
Methods
# checkServerStarted (URL: string, headers: string) → boolean inner
Perform check somebody listen on URL
# establishConnectionFromCmdLineAttributes (configopt: object) → ServerSession inner
Service function for establish UnityBase server connection from client-side command line script.
Parse command line attributes for switches host
, u
, p
and:
- Check specified server is started (simple request to
host
) and if not started then start server locally with local config - Establish connection to specified host
- Retrieve application information and in case authorization is required then call login method using
u
andp
params - Return serverSession object with connection in case of success or throw assertion error
# getConfigFileName () → string inner
Get config file name. if -cfg switch passed then use this switch value, else use default
# getServerConfiguration (forFutureSaveopt: boolean) → object inner
Read server configuration from file, resolved by getConfigFileName parse it in safe mode, replace environment variables by it values and return parsed config
In server thread use App.serverConfig
to read already parsed server configuration.
Arguments:
forFutureSave
= false: booleanIf true will return config ready to save back as new ubConfig (do not add props model.browser & model.version)
# safeParseJSONfile (fileName: string, allowMultiLineStringopt: boolean, preprocessoropt: function) → object inner
JSON file parsing, allow to parse semi-JSON files with comments. In case of errors inside JSON show detailed error description
# serverSessionFromCmdLineAttributes () → ServerSession inner
Parse cmd line and environment variables for command line parameters expected by UnityBase cmd
mode
# serverURLFromConfig (config: object) inner
Return a URL server actually listen on
Arguments:
config
: objectServer configuration
# setServerConfiguration (newCfg: string) inner
Set a configuration for native part of UB server WARNING - in case domain already initialized by native this value is ignored until stopServer() is called