Adjust paths to handle CORS changes (#2816)

* Adjust :8080 paths for CORS & development

* No need to redirect, Node takes care of it
This commit is contained in:
Jaco Greeff 2016-10-24 12:21:52 +02:00 committed by Gav Wood
parent e5f86c62ad
commit 7e84b078dd
8 changed files with 23 additions and 17 deletions

View File

@ -16,6 +16,8 @@
import React from 'react'; import React from 'react';
import { parityNode } from '../../../environment';
const styles = { const styles = {
padding: '.5em', padding: '.5em',
border: '1px solid #777' border: '1px solid #777'
@ -23,7 +25,7 @@ const styles = {
export default (address) => ( export default (address) => (
<img <img
src={ `http://127.0.0.1:8080/${address}/` } src={ `${parityNode}/${address}/` }
alt={ address } alt={ address }
style={ styles } style={ styles }
/> />

View File

@ -30,6 +30,7 @@ import styles from './token.css';
import { metaDataKeys } from '../../constants'; import { metaDataKeys } from '../../constants';
import { api } from '../../parity'; import { api } from '../../parity';
import { parityNode } from '../../../../environment';
export default class Token extends Component { export default class Token extends Component {
static propTypes = { static propTypes = {
@ -267,7 +268,7 @@ export default class Token extends Component {
</span> meta-data: </span> meta-data:
</p> </p>
<div className={ styles['meta-image'] }> <div className={ styles['meta-image'] }>
<img src={ `http://127.0.0.1:8080/api/content/${imageHash}/` } /> <img src={ `${parityNode}/api/content/${imageHash}/` } />
</div> </div>
</div>); </div>);
} }

View File

@ -18,3 +18,9 @@
// import './perf-debug'; // import './perf-debug';
import './tests'; import './tests';
const parityNode = process.env.NODE_ENV === 'production' ? 'http://127.0.0.1:8080' : '';
export {
parityNode
};

View File

@ -17,12 +17,6 @@
import 'babel-polyfill'; import 'babel-polyfill';
import 'whatwg-fetch'; import 'whatwg-fetch';
// redirect when not on 127.0.0.1:8180
const host = `${window.location.hostname}:${window.location.port}`;
if (host === '127.0.0.1:8080' || host === 'localhost:8080') {
window.location = 'http://127.0.0.1:8180';
}
import es6Promise from 'es6-promise'; import es6Promise from 'es6-promise';
es6Promise.polyfill(); es6Promise.polyfill();

View File

@ -17,6 +17,8 @@
import { handleActions } from 'redux-actions'; import { handleActions } from 'redux-actions';
import { bytesToHex } from '../../api/util/format'; import { bytesToHex } from '../../api/util/format';
import { parityNode } from '../../environment';
const ZERO = '0x0000000000000000000000000000000000000000000000000000000000000000'; const ZERO = '0x0000000000000000000000000000000000000000000000000000000000000000';
const initialState = { const initialState = {
@ -26,7 +28,7 @@ const initialState = {
export function hashToImageUrl (hashArray) { export function hashToImageUrl (hashArray) {
const hash = hashArray ? bytesToHex(hashArray) : ZERO; const hash = hashArray ? bytesToHex(hashArray) : ZERO;
return hash === ZERO ? null : `http://127.0.0.1:8080/api/content/${hash.substr(2)}`; return hash === ZERO ? null : `${parityNode}/api/content/${hash.substr(2)}`;
} }
export default handleActions({ export default handleActions({

View File

@ -16,6 +16,8 @@
import { statusBlockNumber, statusCollection, statusLogs } from './statusActions'; import { statusBlockNumber, statusCollection, statusLogs } from './statusActions';
import { parityNode } from '../../environment';
export default class Status { export default class Status {
constructor (store, api) { constructor (store, api) {
this._api = api; this._api = api;
@ -49,7 +51,7 @@ export default class Status {
setTimeout(this._pollPing, timeout); setTimeout(this._pollPing, timeout);
}; };
fetch('/', { method: 'GET' }) fetch(`${parityNode}/api/ping`, { method: 'GET' })
.then((response) => dispatch(!!response.ok)) .then((response) => dispatch(!!response.ok))
.catch(() => dispatch(false)); .catch(() => dispatch(false));
} }

View File

@ -18,10 +18,7 @@ import React, { Component, PropTypes } from 'react';
import styles from './dapp.css'; import styles from './dapp.css';
const hostname = `${window.location.hostname}:${window.location.port}`; const dapphost = process.env.NODE_ENV === 'production' ? 'http://127.0.0.1:8080/ui' : '';
const dapphost = (hostname === 'localhost:3000') || (hostname === '127.0.0.1:3000')
? hostname
: '127.0.0.1:8080/ui';
export default class Dapp extends Component { export default class Dapp extends Component {
static propTypes = { static propTypes = {
@ -31,7 +28,7 @@ export default class Dapp extends Component {
render () { render () {
const { name, type } = this.props.params; const { name, type } = this.props.params;
const src = type === 'global' const src = type === 'global'
? `http://${dapphost}/${name}.html` ? `${dapphost}/${name}.html`
: `http://127.0.0.1:8080/${name}/`; : `http://127.0.0.1:8080/${name}/`;
return ( return (

View File

@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
import { parityNode } from '../../environment';
const builtinApps = [ const builtinApps = [
{ {
id: '0xf9f2d620c2e08f83e45555247146c62185e4ab7cf82a4b9002a265a0d020348f', id: '0xf9f2d620c2e08f83e45555247146c62185e4ab7cf82a4b9002a265a0d020348f',
@ -72,7 +74,7 @@ const builtinApps = [
]; ];
export default function () { export default function () {
return fetch('http://127.0.0.1:8080/api/apps') return fetch(`${parityNode}/api/apps`)
.then((response) => { .then((response) => {
return response.ok return response.ok
? response.json() ? response.json()
@ -84,7 +86,7 @@ export default function () {
}) })
.then((localApps) => { .then((localApps) => {
return builtinApps return builtinApps
.concat(localApps) .concat(localApps.filter((app) => !['ui'].includes(app.id)))
.sort((a, b) => a.name.localeCompare(b.name)); .sort((a, b) => a.name.localeCompare(b.name));
}); });
} }