Use the window location origin as the API origin (#217)

This commit is contained in:
Mike Stone 2016-09-20 18:36:36 -04:00 committed by Mike Arpaia
parent 7a30db5772
commit eb13b33b4d
2 changed files with 6 additions and 17 deletions

View file

@ -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;

View file

@ -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;
}