This documentation describe native
(implemented inside ub.exe) methods,
but developer can add his own (custom) application level methods using App.registerEndpoint
and take a full control on HTTP request & response.
Mixes EventEmitter, and server will emit:
endpointName + ':before'
event before endpoint handler executionendpointName + ':after'
event after success (no exception is raised, no App.preventDefault() is called) endpoint handler execution
This happens for both native and custom methods.
- Mixes In:
Members
name: String
static
readonly
Application name
staticPath: String
static
readonly
Full path to application static folder if any, '' if static folder not set
serverURL: String
static
readonly
Full URl HTTP server is listen on (if HTTP server enabled, else - empty string)
localIPs
static
List of a local server IP addresses CRLF (or CR for non-windows) separated
domain: TubDomain
static
readonly
Current application Domain
- Deprecated:
- UB >=4 use a App.domainInfo - a pure JS domain representation
domainInfo: UBDomain
static
A domain model (metadata) definition for current application
defaultDatabase: TubDatabase
static
Default database connection
customSettings: String
static
Custom settings for application from ubConfig.app.customSettings
emitterEnabled: Boolean
static
Is event emitter enabled for App singleton. Default is false
- Deprecated:
- Starting from 1.11 this property ignored (always TRUE)
serverPublicCert: string
static
Defense edition only,
Base64 encoded public server certificate
Contains non empty value in case security.dstu.trafficEncryption === true and
key name defined in security.dstu.novaLib.keyName
serverConfig: Object
static
Server configuration (result of argv.getServerConfiguration() execution)
databases_: Object.<string, TubDatabase_>
static
Databases of application
Properties:
- UB >=4 use a App.domainInfo - a pure JS domain representation
- Starting from 1.11 this property ignored (always TRUE)
Contains non empty value in case security.dstu.trafficEncryption === true and key name defined in security.dstu.novaLib.keyName
Name | Type | Description |
---|---|---|
databases_ |
defaultDatabase_: TubDatabase_ static
Properties:
Name | Type | Description |
---|---|---|
defaultDatabase_ |
Methods
preventDefault()
static
Accessible inside app-level :before
event handler. Call to prevent default method handler.
In this case developer are responsible to fill response object, otherwise HTTP 400 is returned.
registerEndpoint(endpointName, handler, requireAuthenticationopt)
static
Register a server endpoint. By default access to endpoint require authentication
Arguments:
Example
// Write a custom request body to file FIXTURES/req and echo file back to client
// @param {THTTPRequest} req
// @param {THTTPResponse} resp
//
function echoToFile(req, resp) {
var fs = require('fs');
fs.writeFileSync(FIXTURES + 'req', req.read('bin'));
resp.statusCode = 200;
resp.writeEnd(fs.readFileSync(FIXTURES + 'req', {encoding: 'bin'}));
}
App.registerEndpoint('echoToFile', echoToFile);
addAppLevelMethod(methodName)
static
Arguments:
-
methodName
(String)
- Deprecated:
- Use
App.registerEndpoint
instead
serviceMethodByPassAuthentication(methodName)
static
Arguments:
-
methodName
(String)
- Deprecated:
- Use
App.registerEndpoint
instead
resolveStatic(aRequestedFile) → String
protected
static
Resolve aRequestedFile to real file path.
Internally analyse request and if it start with model/
- resolve it to model public folder
else - to inetPub
folder.
Will return '' in case of error (filePath not under inetPub
or model/
) to prevent ../../ attack
Arguments:
-
aRequestedFile
(String)
fileChecksum(pathToFile) → string
static
First check in global cache for a entry "UB_GLOBAL_CACHE_CHECKSUM + filePath"
and if not exists - calculate a checksum using algorithm defined in
CONTROLLER.serverConfig.HTTPServer.watchFileChanges.hashingStrategy
if server in dev mode always return current timestamp
values from cache will be cleared in directoryNotifiers
Arguments:
-
pathToFile
(String)
folderChecksum(pathToFolder) → string
static
A folder checksum (see fileChecksum for algorithm details)
Arguments:
-
pathToFolder
globalCacheGet(key) → String
static
Get value from global cache. Global cache shared between all threads.
Return '' (empty string) in case key not present in cache.
Arguments:
-
key
(String)
 Key to retrive
globalCachePut(key, value)
static
Put value to global cache.
Arguments:
authFromRequest() → Boolean
static
Try retrieve or create new session from request header
Return true if success
els(entityCode, methodCode) → boolean
static
Check Entity-Level-Security for specified entity/method
if App.els('uba_user', 'insert'){
// do something
}
Arguments:
getUISettings() → string
static
Return JSON specified in serverConfig.uiSettings
deleteFromFTSIndex(entityName, instanceID)
static
Delete row from FTS index for exemplar with instanceID
of entity entityName
(mixin fts
must be enabled for entity)
Arguments:
updateFTSIndex(entityName, instanceID)
static
Update FTS index for for exemplar with instanceID
of entity entityName
(mixin fts
must be enabled for entity).
In case row dose not exist in FTS perform insert action automatically.
Arguments:
dbInTransaction(connectionName) → Boolean
static
Check database are used in current endpoint context and DB transaction is already active
Arguments:
-
connectionName
(String)
dbCommit(connectionNameopt) → Boolean
static
Commit active database transaction if any.
In case connectionName
is not passed will commit all active transactions for all connections.
Return true
if transaction is comitted, or false
if database not in use or no active transaction.
Arguments:
-
[connectionName]
(String)
dbRollback(connectionNameopt) → Boolean
static
Rollback active database transaction if any.
In case connectionName
is not passed will rollback all active transactions for all connections.
Return true
if transaction is rollback'ed, or false
if database not in use or no active transaction.
Arguments:
-
[connectionName]
(String)
dbStartTransaction(connectionName) → Boolean
static
Start a transaction for a specified database. If database is not used in this context will
create a connection to the database and start transaction.
For Oracle with DBLink first statement to DBLink'ed table must be
either update/insert/delete or you MUST manually start transaction
to prevent "ORA-01453: SET TRANSACTION be first statement"
Arguments:
-
connectionName
(String)
:before
event handler. Call to prevent default method handler.
In this case developer are responsible to fill response object, otherwise HTTP 400 is returned.
// Write a custom request body to file FIXTURES/req and echo file back to client
// @param {THTTPRequest} req
// @param {THTTPResponse} resp
//
function echoToFile(req, resp) {
var fs = require('fs');
fs.writeFileSync(FIXTURES + 'req', req.read('bin'));
resp.statusCode = 200;
resp.writeEnd(fs.readFileSync(FIXTURES + 'req', {encoding: 'bin'}));
}
App.registerEndpoint('echoToFile', echoToFile);
methodName
(String)
- Use
App.registerEndpoint
instead
methodName
(String)
- Use
App.registerEndpoint
instead
model/
- resolve it to model public folder
else - to inetPub
folder.
Will return '' in case of error (filePath not under inetPub
or model/
) to prevent ../../ attack
aRequestedFile
(String)
pathToFile
(String)
pathToFolder
Return '' (empty string) in case key not present in cache.
key
(String)
 Key to retrive
Return true if success
Check Entity-Level-Security for specified entity/method
if App.els('uba_user', 'insert'){
// do something
}
instanceID
of entity entityName
(mixin fts
must be enabled for entity)
instanceID
of entity entityName
(mixin fts
must be enabled for entity).
In case row dose not exist in FTS perform insert action automatically.
connectionName
(String)
connectionName
is not passed will commit all active transactions for all connections.
Return true
if transaction is comitted, or false
if database not in use or no active transaction.
[connectionName]
(String)
connectionName
is not passed will rollback all active transactions for all connections.
Return true
if transaction is rollback'ed, or false
if database not in use or no active transaction.
[connectionName]
(String)
For Oracle with DBLink first statement to DBLink'ed table must be either update/insert/delete or you MUST manually start transaction to prevent "ORA-01453: SET TRANSACTION be first statement"
connectionName
(String)