Skip to content

Commit

Permalink
Add NETSTATS_API_URL=self for rev. proxy of api
Browse files Browse the repository at this point in the history
  • Loading branch information
valer-cara committed Oct 24, 2019
1 parent f02ab59 commit 419d1bd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/components/ConnectNodeModal/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { connect } from 'react-redux';
import axios from 'axios';
import { NETSTATS_API_URL } from 'config';
import { netstatsApiUrl } from 'utils/helpers';
import onClickOutside from 'react-onclickoutside';
import PropTypes from 'prop-types';
import { hideConnectNodeModal as hideConnectNodeModalAction} from 'actions/global';
Expand Down Expand Up @@ -66,7 +66,7 @@ class ConnectNodeModal extends React.Component {
nodeName: this.state.nodeName,
accountEmail: this.state.email,
};
axios.post(`${NETSTATS_API_URL}/nodes`, user)
axios.post(`${netstatsApiUrl()}/nodes`, user)
.then(res => {
if (res.data.body.success) {
this.setState({
Expand Down
4 changes: 2 additions & 2 deletions app/netstatsApi.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import axios from 'axios';
import { NETSTATS_API_URL } from 'config';
import { netstatsApiUrl } from 'utils/helpers';

const axiosApiInstance = axios.create({
baseURL: NETSTATS_API_URL,
baseURL: netstatsApiUrl(),
});

export function getInitialNodeHistory(nodeName) {
Expand Down
11 changes: 11 additions & 0 deletions app/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { ScriptLoader } from "@puzzl/browser/lib/network/ScriptLoader";
import moment from 'moment/moment';
import _ from 'lodash';

import { NETSTATS_API_URL } from 'config';

export function trimValue(string, digits = 4) {
string = string.replace('0x', '');
return `${string.substr(0, digits)} ... ${string.substr(-digits)}`;
Expand Down Expand Up @@ -393,3 +395,12 @@ export function initGoogleAnalytics(gaId) {

gtag("config", gaId);
}

export function netstatsApiUrl() {
const currentHost = location.protocol + '//' +
location.hostname +
(location.port ? ':' + location.port: '');

return NETSTATS_API_URL !== "self" ? NETSTATS_API_URL : currentHost;
}

0 comments on commit 419d1bd

Please sign in to comment.