Use the window location origin as the API origin (#217)
This commit is contained in:
@@ -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;
|
||||
|
||||
+3
-16
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user