Skip to content

Commit

Permalink
Merge pull request #723 from StackStorm/fix/st2web-http
Browse files Browse the repository at this point in the history
Fix st2web to also work on http
  • Loading branch information
armab authored Jun 4, 2019
2 parents 263ffda + 5d0cd83 commit 6247b56
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
6 changes: 3 additions & 3 deletions modules/st2-api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ export class API {
}
else {
this.server = {
api: `https://${window.location.host}/api`,
auth: `https://${window.location.host}/auth`,
stream: `https://${window.location.host}/stream`,
api: `${window.location.protocol || 'https:'}//${window.location.host}/api`,
auth: `${window.location.protocol || 'https:'}//${window.location.host}/auth`,
stream: `${window.location.protocol || 'https:'}//${window.location.host}/stream`,
token: !_.isEmpty(token) ? token : null,
};
}
Expand Down
21 changes: 21 additions & 0 deletions modules/st2-api/tests/test-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,27 @@ describe('API', () => {
window.location.host = host; // restore initial value
});

describe('can work with http', () => {
// capture initial value
const host = window.location.host;
const protocol = window.location.protocol;

// set test value
window.location.host = 'www.example.net:1234';
window.location.protocol = 'http:';

const api = new API();
api.connect();

expect(api.server.api).to.equal('http://www.example.net:1234/api');
expect(api.server.auth).to.equal('http://www.example.net:1234/auth');
expect(api.server.stream).to.equal('http://www.example.net:1234/stream');

// restore initial value
window.location.host = host;
window.location.protocol = protocol;
});

describe('connect', () => {
before(() => moxios.install());
after(() => moxios.uninstall());
Expand Down

0 comments on commit 6247b56

Please sign in to comment.