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 (URLstring, headersstring) → boolean inner

Perform check somebody listen on URL

Arguments:

# establishConnectionFromCmdLineAttributes (configoptobject) → 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
    • hoststring

    • userstring

    • pwdstring

    • headersstring

      Stringify object with default HTTP request headers

    • forceStartServerboolean

      If we sure local server not started - start it without checking. Faster because check take near 2 sec.

    • timeout=30000number

      Receive timeout in ms

# getConfigFileName () → string inner

Get config file name. if -cfg switch passed then use this switch value, else use default

# getServerConfiguration (forFutureSaveoptboolean) → 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: boolean

    If true will return config ready to save back as new ubConfig (do not add props model.browser & model.version)

# safeParseJSONfile (fileNamestring, allowMultiLineStringoptboolean, preprocessoroptfunction) → 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

# serverSessionFromCmdLineAttributes () → ServerSession inner

Parse cmd line and environment variables for command line parameters expected by UnityBase cmd mode

# serverURLFromConfig (configobject) inner

Return a URL server actually listen on

Arguments:
  • config: object

    Server configuration

# setServerConfiguration (newCfgstring) 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

Arguments: