Skip to content

Commit

Permalink
API-3 - Extend API Info response
Browse files Browse the repository at this point in the history
  • Loading branch information
macbookpro committed May 21, 2024
1 parent b5e99a6 commit cac5d72
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
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 () => {
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

0 comments on commit cac5d72

Please sign in to comment.