mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
Use the window location origin as the API origin (#217)
This commit is contained in:
parent
7a30db5772
commit
eb13b33b4d
2 changed files with 6 additions and 17 deletions
|
|
@ -1,6 +1,8 @@
|
|||
import jsdom from 'jsdom';
|
||||
|
||||
const doc = jsdom.jsdom('<!doctype html><html><body></body></html>');
|
||||
const doc = jsdom.jsdom('<!doctype html><html><body></body></html>', {
|
||||
url: 'http://localhost:8080/foo',
|
||||
});
|
||||
|
||||
global.document = doc;
|
||||
global.window = doc.defaultView;
|
||||
|
|
|
|||
|
|
@ -1,27 +1,14 @@
|
|||
import fetch from 'isomorphic-fetch';
|
||||
|
||||
import config from '../config';
|
||||
import local from '../utilities/local';
|
||||
|
||||
class Base {
|
||||
constructor () {
|
||||
this.baseURL = this.setBaseURL();
|
||||
const { origin } = global.window.location;
|
||||
|
||||
this.baseURL = `${origin}/api`;
|
||||
this.bearerToken = local.getItem('auth_token');
|
||||
}
|
||||
|
||||
setBaseURL () {
|
||||
const {
|
||||
settings: { env },
|
||||
environments: { development },
|
||||
} = config;
|
||||
|
||||
if (env === development) {
|
||||
return 'http://localhost:8080/api';
|
||||
}
|
||||
|
||||
throw new Error(`API base URL is not configured for environment: ${env}`);
|
||||
}
|
||||
|
||||
setBearerToken (bearerToken) {
|
||||
this.bearerToken = bearerToken;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue