Utils for connecting to a local UnityBase server
In case you need to work with command line use a @unitybase/base.options
module
Example
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
static
- Deprecated:
- Use `options.switchIndex' instead
findCmdLineSwitchValue
static
- Deprecated:
- Use `options.switchValue' instead
Methods
getConfigFileName() → String
inner
Get config file name. if -cfg switch passed then use this switch value, else use default
serverSessionFromCmdLineAttributes() → ServerSession
inner
Parse cmd line and environment variables for command line parameters expected by UnityBase cmd
mode
establishConnectionFromCmdLineAttributes(configopt) → 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
and p
params
- Return serverSession object with connection in case of success or throw assertion error
Arguments:
-
[config]
(Object)
Properties
checkServerStarted(URL) → boolean
inner
Perform check somebody listen on URL
Arguments:
-
URL
(String)
getServerConfiguration() → Object
inner
Read server configuration using file, resolved by argv.getConfigFileName
parse it in safe mode, replace environment variables by it values and return parsed config
serverURLFromConfig(config)
inner
Return a URL server actually listen on
Arguments:
-
config
(Object)
 Server configuration
safeParseJSONfile(fileName, allowMultiLineStringopt, preprocessoropt) → Object
inner
JSON file parsing, allow to parse semi-JSON files with comments. In case of errors inside JSON show detailed error description
Arguments:
-
fileName
(String)
-
[allowMultiLineString=false]
(Boolean)
 Replace \n
before parse (not compatible with JSON format, but multiline string is useful)
-
[preprocessor]
(function)
 Optional function accept file content transform it and return new content
- Use `options.switchIndex' instead
- Use `options.switchValue' instead
getConfigFileName() → String inner
Get config file name. if -cfg switch passed then use this switch value, else use default
serverSessionFromCmdLineAttributes() → ServerSession inner
Parse cmd line and environment variables for command line parameters expected by UnityBase
cmd
mode
establishConnectionFromCmdLineAttributes(configopt) → 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
Arguments:
-
[config]
(Object)
Properties
checkServerStarted(URL) → boolean inner
Perform check somebody listen on URL
Arguments:
-
URL
(String)
getServerConfiguration() → Object inner
Read server configuration using file, resolved by argv.getConfigFileName
parse it in safe mode, replace environment variables by it values and return parsed config
serverURLFromConfig(config) inner
Return a URL server actually listen on
Arguments:
-
config
(Object)
 Server configuration
safeParseJSONfile(fileName, allowMultiLineStringopt, preprocessoropt) → Object inner
JSON file parsing, allow to parse semi-JSON files with comments. In case of errors inside JSON show detailed error description
Arguments:
-
fileName
(String)
-
[allowMultiLineString=false]
(Boolean)
 Replace\n
before parse (not compatible with JSON format, but multiline string is useful) -
[preprocessor]
(function)
 Optional function accept file content transform it and return new content