-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #154 from forio/api-server-config
EPICENTER-1725: Load the api configuration from the server
- Loading branch information
Showing
6 changed files
with
98 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict'; | ||
|
||
var urlConfigService = require('./service/url-config-service'); | ||
|
||
var envLoad = function (callback) { | ||
var envPromise; | ||
var host; | ||
var urlService = urlConfigService(); | ||
var envPath = '/epicenter/v1/config'; | ||
if (urlService.isLocalhost()) { | ||
envPromise = $.Deferred(); | ||
envPromise.resolve(); | ||
host = 'https://forio.com'; | ||
} else { | ||
host = ''; | ||
} | ||
var infoUrl = host + envPath; | ||
envPromise = $.ajax({ url: infoUrl, async: false }); | ||
envPromise.done(function (res) { | ||
var api = res.api; | ||
$.extend(urlConfigService, api); | ||
}); | ||
envPromise.done(callback).fail(callback); | ||
}; | ||
|
||
module.exports = envLoad; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
(function () { | ||
'use strict'; | ||
describe('Env Load', function () { | ||
var server; | ||
beforeEach(function () { | ||
server = sinon.fakeServer.create(); | ||
|
||
var env = { | ||
api: { | ||
host: 'api.forio.com', | ||
protocol: 'https' | ||
} | ||
}; | ||
// API Config | ||
server.respondWith('GET', /forio\.com\/epicenter\/v1\/config/, function (xhr, id) { | ||
xhr.respond(200, { 'Content-Type': 'application/json' }, JSON.stringify(env)); | ||
}); | ||
|
||
server.autoRespond = true; | ||
}); | ||
|
||
afterEach(function () { | ||
server.restore(); | ||
}); | ||
|
||
describe('load', function () { | ||
it('it should request the server env url', function () { | ||
F.load(); | ||
|
||
var req = server.requests.pop(); | ||
req.method.toUpperCase().should.equal('GET'); | ||
req.url.should.equal('https://forio.com/epicenter/v1/config'); | ||
}); | ||
|
||
it('it should set protocol and host to the UrlConfingService', function () { | ||
delete F.service.URL.protocol; | ||
delete F.service.URL.host; | ||
F.load(function () { | ||
F.service.URL.protocol.should.equal('https'); | ||
F.service.URL.host.should.equal('api.forio.com'); | ||
delete F.service.URL.protocol; | ||
delete F.service.URL.host; | ||
}); | ||
}); | ||
}); | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters