Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ class Backendless {

app.__removeService('LocalCache')

app.appInfoPromise()

const loggingConfig = Object.assign({ loadLevels: true, globalLevel: 'all', levels: {} }, config.logging)

if (app.__hasService('Logging')) {
Expand All @@ -166,6 +168,18 @@ class Backendless {
return app
}

appInfoPromise() {
if (!this.__appInfoPromise) {
this.__appInfoPromise = new Promise((resolve, reject) => {
this.request.get({ url: this.urls.appInfo() })
.then(resolve)
.catch(reject);
})
}

return this.__appInfoPromise
}

__hasService(name) {
return !!this[`__${name}`]
}
Expand Down
6 changes: 3 additions & 3 deletions src/logging/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ export default class Logging {
}

loadLoggingLevels() {
this.app.request
.get({ url: this.app.urls.loggingLevels() })
.then(loggersList => {
this.app.appInfoPromise()
.then(appInfo => {
const { loggers: loggersList } = appInfo
const loggers = {}

loggersList.forEach(logger => {
Expand Down
16 changes: 6 additions & 10 deletions src/rt.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
import Request from 'backendless-request'
import BackendlessRTClient from 'backendless-rt-client'

import Utils from './utils'

export const RTListeners = BackendlessRTClient.Listeners
export const RTScopeConnector = BackendlessRTClient.ScopeConnector

function loadAppInfo(appPath) {
return Request.get(`${appPath}/info`)
}

export default class RT extends BackendlessRTClient {
constructor(app) {
const { appId, apiKey, appPath, debugMode } = app
const { appId, apiKey, debugMode } = app

const clientId = Utils.uuid()
const lookupPath = `${appPath}/rt/lookup`

super({
appId: appId || undefined,
lookupPath,
debugMode,
connectQuery() {
const userToken = app.getCurrentUserToken()
Expand All @@ -31,10 +24,13 @@ export default class RT extends BackendlessRTClient {
}
},

getAppInfo: async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hostResolver(){
  return app.appInfoPromise().then(({ rtURL })=> rtURL)
}

return await app.appInfoPromise()
},

socketConfigTransform: async socketConfig => {
if (!appId) {
const appInfo = await loadAppInfo(appPath)

const appInfo = await app.appInfoPromise()
socketConfig.url = `${socketConfig.host}/${appInfo.appId}`
socketConfig.options.path = `/${appInfo.appId}`
socketConfig.options.query.apiKey = appInfo.apiKey
Expand Down
6 changes: 6 additions & 0 deletions src/urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ export default class Urls {
return this.app.appPath
}

// app info

appInfo() {
return `${this.root()}/info`
}

//automations

automation() {
Expand Down