The server object that provides access to the following server-based functions:
The server object also has generic methods to aid in fetching server results and methods to invoke server-based functions. See server fetch methods and server API methods.
The server.baseUrl property contains the URL for the root of the server serving the API. By default, this is set to the origin server. However, the app can be invoked in a variety of environments: from an Internet server, from a local HTTP server, and from within a Cordova native app. In each case, the app.js startup file, can decide where the server resides by setting server.baseUrl. For example, POH Performance apps invoked in a Cordova native app set server.baseUrl to https://pohperformance.com/${appId}.
server fetch methodsThe fetch methods in the server object provide a simplified interface to the fetch() function.
server.fetch()fetch() function optimized for passing requests with arguments and providing a timeout capability.server.get()server.fetch() specifying the GET method.server.post()server.fetch() specifying the POST method.server.stdOp()server.fetch() specifying the POST method and added arguments shared by all standard MVCS API functions.fetch()server.fetch(url, method)
server.fetch(url, method, args)
server.fetch(url, method, args, options)
server.fetch(url, method, args, options, timeout)
Fetches the url using the method ('GET' or 'POST'), passing the arguments in the args object, and returns a Promise that resolves to the fetched Response if the Response status is OK (HTTP status code 200). If the Response is not OK, then the Response is passed as the rejection of the Promise.
If timeout is provided and non-zero, the request will time out in the specified number of milliseconds. If timeout is omitted, then it defaults to the value specified by the server.timeout property, which is set to 20 seconds initially. If the timeout expires, the Promise is rejected with a Response code of 524 (Connection Timed Out).
urlmethod'GET': Use the GET method.'POST': Use the POST method.args (optional)options (optional)fetch(). If not provided this defaults to an empty Object. POST requests will fill options.body with the arguments.timeout (optional)timeout is 0, then the fetch will wait for a response without a timeout. If timeout is omitted, then it defaults to the value in server.timeout, which is set to 20 seconds initially.A Promise that resolves with the returned Response if the status is OK. Otherwise, the promise is rejected with the returned or timeout Response.
get()server.get(url)
server.get(url, args)
server.get(url, args, options)
server.get(url, args, options, timeout)
Fetches the url using the GET method, passing the arguments in the args object, and returns a Promise that resolves to the fetched Response if the Response status is OK (HTTP status code 200). If the Response is not OK, then the Response is passed as the rejection of the Promise.
If timeout is provided and non-zero, the request will time out in the specified number of milliseconds. If timeout is omitted, then it defaults to the value specified by the server.timeout property, which is set to 20 seconds initially. If the timeout expires, the Promise is rejected with a Response code of 524 (Connection Timed Out).
urlargs (optional)options (optional)fetch(). If not provided this defaults to an empty Object. POST requests will fill options.body with the arguments.timeout (optional)timeout is 0, then the fetch will wait for a response without a timeout. If timeout is omitted, then it defaults to the value in server.timeout, which is set to 20 seconds initially.A Promise that resolves with the returned Response if the status is OK. Otherwise, the promise is rejected with the fetch Response or timeout Response.
post()server.post(url)
server.post(url, args)
server.post(url, args, options)
server.post(url, args, options, timeout)
Fetches the url using the POST method, passing the arguments in the args object, and returns a Promise that resolves to the fetched Response if the Response status is OK (HTTP status code 200). If the Response is not OK, then the Response is passed as the rejection of the Promise.
If timeout is provided and non-zero, the request will time out in the specified number of milliseconds. If timeout is omitted, then it defaults to the value specified by the server.timeout property, which is set to 20 seconds initially. If the timeout expires, the Promise is rejected with a Response code of 524 (Connection Timed Out).
urlargs (optional)options (optional)fetch(). If not provided this defaults to an empty Object. POST requests will fill options.body with the arguments.timeout (optional)timeout is 0, then the fetch will wait for a response without a timeout. If timeout is omitted, then it defaults to the value in server.timeout, which is set to 20 seconds initially.A Promise that resolves with the returned Response if the status is OK. Otherwise, the promise is rejected with the fetch Response or timeout Response.
stdOp()server.stdOp(op, opVersion)
server.stdOp(op, opVersion, args)
server.stdOp(op, opVersion, args, options)
server.stdOp(op, opVersion, args, options, timeout)
Fetches the server op URL using the POST method, passing the arguments in the args object and standard arguments. The URL is constructed as /${ctl.appId}/${op}${server.opSuffix}. The standard arguments are:
appVersionctl.appVersion.opVersionopVersion argument.idserver.id. In recent app versions (post 5.0.0 for POH Performance apps) server.id is set to a JSON string containing an object with email, password, and guid elements.In addition, server.stdOp() sets HTTP request headers to disable caching.
server.stdOp() returns a Promise that resolves to the fetched Response if the Response status is OK (HTTP status code 200). If the Response is not OK, then the Response is passed as the rejection of the Promise.
If timeout is provided and non-zero, the request will time out in the specified number of milliseconds. If timeout is omitted, then it defaults to the value specified by the server.timeout property, which is set to 20 seconds initially. If the timeout expires, the Promise is rejected with a Response code of 524 (Connection Timed Out).
op'startSession', 'getSavedInput'). Used to construct the request URL as /${ctl.appId}/${op}${server.opSuffix}.opVersion'1', '2'). Passed to the server as part of the request body.args (optional)options (optional)fetch(). If not provided this defaults to an empty Object.timeout (optional)timeout is 0, then the fetch will wait for a response without a timeout. If timeout is omitted, then it defaults to the value in server.timeout, which is set to 20 seconds initially.A Promise that resolves with the returned Response if the status is OK. Otherwise, the promise is rejected with the fetch Response or timeout Response.
server API methodsThe server API methods are functions that invoke server API operations. All server API methods call the server.stdOp() method to pass the standard arguments, in addition to ant argument unique to the operation. They fall into the following categories:
set_trData that has additional information, including the problem description and state variable values not normally included when saving.
archiveTr()server.archiveTr(trId)
Archive Trouble Report trId. The trId must be a valid Trouble Report ID created by the setTr() method. Once archived, the server will no longer consider it an outstanding Trouble Report and will not remind the Webmaster about it. Returns a Promise that either resolves to indicate success or rejects with a status code to indicate the failure.
server.archiveTr() calls server.stdOp() to pass the standard headers and arguments in addition to the supplied arguments.
trIdA Promise that resolves with the returned Response if the status is OK. No data is returned in the Response. Otherwise, the Promise is rejected with the returned or timeout Response. The Response can contain the following status codes:
deleteUserData()server.deleteUserData()
Delete all the data associated with server.id. Returns a Promise that resolves with a Response. The Promise rejects if something goes wrong.
server.deleteUserData() calls server.stdOp() to pass the standard headers and arguments.
A Promise that resolves with the returned Response if the status is OK. If the Promise is rejected, the value is the returned Response, or a timeout Response. The Response can contain the following status codes:
getBackups()server.getBackups()
Get all the backups associated with server.id. Returns a Promise that resolves with a Response whose body contains a JSON array of all available backup data. Each backup consists of the data saved by server.setSavedInput(). The data contains a saveTime Date string that can be used to differentiate the backups. If no backups can be found, the array will be empty. The Promise rejects if something goes wrong.
server.getBackups() calls server.stdOp() to pass the standard headers and arguments in addition to the supplied arguments.
A Promise that resolves with the returned Response if the status is OK. The Response body contains a JSON array of all available backup data. If the Promise is rejected, the value is the returned Response, or a timeout Response. The Response can contain the following status codes:
getSavedInput()server.getSavedInput()
Get the saved input associated with server.id. Returns a Promise that resolves with a Response whose body contains a JSON-encoded string of the saved input object. The Promise rejects if something goes wrong.
server.getSavedInput() calls server.stdOp() to pass the standard headers and arguments in addition to the supplied arguments.
A Promise that resolves with the returned Response if the status is OK. The Response body contains a JSON-encoded string of the saved input object. If the Promise is rejected, the value is the returned Response, or a timeout Response. The Response can contain the following status codes:
getTr()server.getTr(trId)
Get the Trouble Report trId. The trId must be a valid Trouble Report ID created by the setTr() method. Returns a Promise that resolves with a Response whose body contains the JSON-encoded string of a saved input object. The Promise rejects if something goes wrong.
server.getTr() calls server.stdOp() to pass the standard headers and arguments in addition to the supplied arguments.
trIdA Promise that resolves with the returned Response if the status is OK. The Response body contains the JSON-encoded string of a saved input object. Otherwise, the Promise is rejected with the returned or timeout Response. The Response can contain the following status codes:
mailSaveIds()server.mailSaveIds()
Recover all passwords associated with the email address within server.id by emailing them to the email address. Returns a Promise that either resolves to indicate success or rejects with a status code to indicate the failure.
server.mailSaveIds() calls server.stdOp() to pass the standard headers and arguments in addition to the supplied arguments.
A Promise that resolves with the returned Response if the status is OK. The Response body contains no data. Otherwise, the Promise is rejected with the returned or timeout Response. The Response can contain the following status codes:
sendEmail()server.sendEmail(to, subject, content)
Email the summarized app results. This is only allowed if there's an existing saved input file associate within server.id. Returns a Promise that either resolves to indicate success or rejects with a status code to indicate the failure.
server.sendEmail() calls server.stdOp() to pass the standard headers and arguments in addition to the supplied arguments.
tosubjectcontentA Promise that resolves with the returned Response if the status is OK. The Response body contains no data. Otherwise, the Promise is rejected with the returned or timeout Response. The Response can contain the following status codes:
id cannot be found.setSavedInput()server.setSavedInput(input)
server.setSavedInput(input, takeover)
Save the input on the server in a file associated with server.id. Returns a Promise that either resolves to indicate success or rejects with a status code to indicate the failure.
If takeover is omitted or false, then the request will be rejected if the guid value in the id does not match the guid field in the currently saved input. If takeover is true, then the input will overwrite any previously saved input.
server.setSavedInput() calls server.stdOp() to pass the standard headers and arguments in addition to the supplied arguments.
A Promise that resolves with the returned Response if the status is OK. The Response body contains no data. Otherwise, the Promise is rejected with the returned or timeout Response. The Response can contain the following status codes:
setTr()server.setTr(data)
Create a Trouble Report that contains data, which is a JSON-encoded saved input string.
Get the Trouble Report trId. The trId must be a valid Trouble Report ID created by the setTr() method. Returns a Promise that resolves with a Response whose body contains a Trouble Report ID (trId) string. The Promise rejects if something goes wrong.
server.setTr() calls server.stdOp() to pass the standard headers and arguments in addition to the supplied arguments.
dataA Promise that resolves with the returned Response if the status is OK. The Response body contains contains a Trouble Report ID (trId) string. Otherwise, the Promise is rejected with the returned or timeout Response. The Response can contain the following status codes:
startSession()server.startSession(info)
Log the start of a user session. The contents of the info argument are attached to the log entry. Typically, this is a JSON-encoded object containing information about the issuing device. Returns a Promise that either resolves to indicate success or rejects with a status code to indicate the failure.
server.startSession() is typically called when the application starts, or the user restarts activity after a significant period of inactivity.
server.startSession() calls server.stdOp() to pass the standard headers and arguments in addition to the supplied arguments.
infoA Promise that resolves with the returned Response if the status is OK. The Response body contains no data. Otherwise, the Promise is rejected with the returned or timeout Response. The Response can contain the following status codes:
server propertiesbaseUrlThe URL for the server root. This is set to the origin root by default. Set his property to something else if a different server is desired.
When in a native app (Cordova), most POH Performance apps will set this to: https://pohperformance.com/${appId}.
A string to use as a base URL.
idThe value of the id argument passed to the fetch() method when using the stdOp() method.
This is typically set to a JSON-encoded object containing email, password, and guid properties.
A string.
isEnabledTrue if the server is enabled. This is set to true by default. Apps that don't use any remote service should set server.isEnabled to false on startup.
A Boolean.
opSuffixA suffix string appended to every operation name when constructing the URL in server.stdOp(). Defaults to ''. Set this property if you want a different default suffix for all operations.
A string.
stdHeadersThe standard headers to include in the fetch() method options when using the stdOp() method.
This is initially set to:
{
'Content-Type': 'application/x-www-form-urlencoded',
}
An object whose properties are HTTP header names and values.
timeoutThe default server operation timeout in milliseconds. This is initially set to 20 seconds.
A number representing the server timeout in milliseconds.