Skip to content

Commit e805464

Browse files
BL-23 - Support setting automation URL (#249)
1 parent 77cf3b5 commit e805464

File tree

4 files changed

+70
-11
lines changed

4 files changed

+70
-11
lines changed

backendless.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ declare module Backendless {
77

88
let debugMode: boolean;
99
let serverURL: string;
10+
let automationServerURL: string;
1011
let appId: string;
1112
let apiKey: string;
1213
let appPath: string;
14+
let automationPath: string;
1315
let domain: string;
1416
let apiURI: string;
1517
let XMLHttpRequest: any;
@@ -35,6 +37,7 @@ declare module Backendless {
3537
apiKey?: string;
3638
standalone?: boolean;
3739
serverURL?: string;
40+
automationServerURL?: string;
3841
domain?: string;
3942
debugMode?: boolean;
4043
XMLHttpRequest?: XMLHttpRequest;

src/index.js

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ import Utils from './utils'
66
import Expression from './expression'
77

88
const DEFAULT_PROPS = {
9-
appId : null,
10-
apiKey : null,
11-
serverURL : 'https://api.backendless.com',
12-
domain : null,
13-
apiURI : '/api',
14-
debugMode : false,
15-
standalone : false,
16-
XMLHttpRequest: typeof XMLHttpRequest !== 'undefined'
9+
appId : null,
10+
apiKey : null,
11+
serverURL : 'https://api.backendless.com',
12+
automationServerURL: null,
13+
domain : null,
14+
apiURI : '/api',
15+
debugMode : false,
16+
standalone : false,
17+
XMLHttpRequest : typeof XMLHttpRequest !== 'undefined'
1718
? XMLHttpRequest
1819
: undefined,
1920
}
@@ -226,8 +227,17 @@ class Backendless {
226227
return this.__serverURL
227228
}
228229

229-
set serverURL(serverURL) {
230-
this.__serverURL = serverURL
230+
set serverURL(url) {
231+
this.__serverURL = url
232+
}
233+
234+
///--------automationServerURL-------///
235+
get automationServerURL() {
236+
return this.__automationServerURL
237+
}
238+
239+
set automationServerURL(url) {
240+
this.__automationServerURL = url
231241
}
232242

233243
///--------domain-------///
@@ -264,6 +274,20 @@ class Backendless {
264274
)
265275
}
266276

277+
get automationPath() {
278+
if (!this.automationServerURL) {
279+
return this.appPath
280+
}
281+
282+
return [this.automationServerURL, this.appId, this.apiKey].join('/')
283+
}
284+
285+
set automationPath(automationPath) {
286+
throw new Error(
287+
`Setting '${automationPath}' value to Backendless.automationPath directly is not possible`
288+
)
289+
}
290+
267291
///--------debugMode-------///
268292
get debugMode() {
269293
return this.__debugMode

src/urls.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default class Urls {
1010
//automations
1111

1212
automation() {
13-
return `${this.root()}/automation`
13+
return `${this.app.automationPath}/automation`
1414
}
1515

1616
automationFlow() {

test/unit/specs/namespace.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ describe('Namespace', function() {
3636
expect(() => Backendless.appId = 'appId').to.throw()
3737
expect(() => Backendless.apiKey = 'apiKey').to.throw()
3838
expect(() => Backendless.appPath = 'appPath').to.throw()
39+
expect(() => Backendless.automationPath = 'automationPath').to.throw()
3940
expect(() => Backendless.standalone = 'standalone').to.throw()
4041
expect(() => Backendless.device = 'device').to.throw()
4142

4243
expect(Backendless.appId).to.be.equal(APP_ID)
4344
expect(Backendless.apiKey).to.be.equal(API_KEY)
4445
expect(Backendless.appPath).to.be.equal(`http://foo.bar/${APP_ID}/${API_KEY}`)
46+
expect(Backendless.automationPath).to.be.equal(`http://foo.bar/${APP_ID}/${API_KEY}`)
4547
})
4648
})
4749

@@ -70,6 +72,32 @@ describe('Namespace', function() {
7072
expect(app1.apiKey).to.be.equal('apiKey-1')
7173
expect(app1.appPath).to.be.equal('http://my-server-url.com/appId-1/apiKey-1')
7274
})
75+
76+
it('has custom automationServerURL', () => {
77+
const app1 = Backendless.initApp({
78+
automationServerURL : 'http://my-automation-server-url.com',
79+
appId : 'appId-1',
80+
apiKey : 'apiKey-1',
81+
standalone: true
82+
})
83+
84+
expect(app1.appId).to.be.equal('appId-1')
85+
expect(app1.apiKey).to.be.equal('apiKey-1')
86+
expect(app1.automationPath).to.be.equal('http://my-automation-server-url.com/appId-1/apiKey-1')
87+
})
88+
89+
it('should take default app path as automationServerURL when no value set', () => {
90+
const app1 = Backendless.initApp({
91+
serverURL : 'http://my-server-url.com',
92+
appId : 'appId-1',
93+
apiKey : 'apiKey-1',
94+
standalone: true
95+
})
96+
97+
expect(app1.appId).to.be.equal('appId-1')
98+
expect(app1.apiKey).to.be.equal('apiKey-1')
99+
expect(app1.automationPath).to.be.equal('http://my-server-url.com/appId-1/apiKey-1')
100+
})
73101
})
74102

75103
describe('Custom Domain', () => {
@@ -81,6 +109,7 @@ describe('Namespace', function() {
81109
expect(Backendless.apiKey).to.be.equal(null)
82110
expect(Backendless.domain).to.be.equal(CUSTOM_DOMAIN)
83111
expect(Backendless.appPath).to.be.equal(`${CUSTOM_DOMAIN}/api`)
112+
expect(Backendless.automationPath).to.be.equal(`${CUSTOM_DOMAIN}/api`)
84113
expect(Backendless.apiURI).to.be.equal('/api')
85114
})
86115

@@ -91,6 +120,7 @@ describe('Namespace', function() {
91120
expect(Backendless.apiKey).to.be.equal(null)
92121
expect(Backendless.domain).to.be.equal(CUSTOM_DOMAIN)
93122
expect(Backendless.appPath).to.be.equal(`${CUSTOM_DOMAIN}/api`)
123+
expect(Backendless.automationPath).to.be.equal(`${CUSTOM_DOMAIN}/api`)
94124
expect(Backendless.apiURI).to.be.equal('/api')
95125
})
96126

@@ -100,6 +130,7 @@ describe('Namespace', function() {
100130

101131
expect(Backendless.domain).to.be.equal(CUSTOM_DOMAIN)
102132
expect(Backendless.appPath).to.be.equal(`${CUSTOM_DOMAIN}/my-api-uri`)
133+
expect(Backendless.automationPath).to.be.equal(`${CUSTOM_DOMAIN}/my-api-uri`)
103134
expect(Backendless.apiURI).to.be.equal('/my-api-uri')
104135

105136
Backendless.apiURI = undefined
@@ -373,6 +404,7 @@ describe('Namespace', function() {
373404
expect(Backendless.apiKey).to.be.equal(null)
374405
expect(Backendless.domain).to.be.equal('https://foo.com')
375406
expect(Backendless.appPath).to.be.equal('https://foo.com/api')
407+
expect(Backendless.automationPath).to.be.equal('https://foo.com/api')
376408
expect(Backendless.apiURI).to.be.equal('/api')
377409

378410
const appIdWarnMsg = 'getter/setter for Backendless.applicationId is deprecated, instead use Backendless.appId'

0 commit comments

Comments
 (0)