Skip to content

Commit 7728372

Browse files
committed
Use PUBLIC_URL throughout the app
See #254. Fixes Fix auth URL
1 parent 5cdec77 commit 7728372

File tree

6 files changed

+27
-19
lines changed

6 files changed

+27
-19
lines changed

app/src/Routes.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Route, Router, Switch } from 'react-router';
33
import { useStore } from 'store';
44
import Loading from 'components/common/Loading';
55
import { Layout } from 'components/layout';
6+
import { PUBLIC_URL } from 'config';
67

78
const LazyAuthPage = React.lazy(() => import('components/auth/AuthPage'));
89
const LazyLoopPage = React.lazy(() => import('components/loop/LoopPage'));
@@ -12,20 +13,19 @@ const LazySettingsPage = React.lazy(() => import('components/settings/SettingsPa
1213

1314
const Routes: React.FC = () => {
1415
const { router } = useStore();
15-
1616
return (
1717
<Suspense fallback={<Loading delay={500} />}>
1818
<Router history={router.history}>
1919
<Switch>
20-
<Route path="/" exact component={LazyAuthPage} />
20+
<Route path={`${PUBLIC_URL}/`} exact component={LazyAuthPage} />
2121
<Route>
2222
<Layout>
2323
<Switch>
2424
<Suspense fallback={<Loading delay={500} />}>
25-
<Route path="/loop" component={LazyLoopPage} />
26-
<Route path="/history" component={LazyHistoryPage} />
27-
<Route path="/pool" component={LazyPoolPage} />
28-
<Route path="/settings" component={LazySettingsPage} />
25+
<Route path={`${PUBLIC_URL}/loop`} component={LazyLoopPage} />
26+
<Route path={`${PUBLIC_URL}/history`} component={LazyHistoryPage} />
27+
<Route path={`${PUBLIC_URL}/pool`} component={LazyPoolPage} />
28+
<Route path={`${PUBLIC_URL}/settings`} component={LazySettingsPage} />
2929
</Suspense>
3030
</Switch>
3131
</Layout>

app/src/components/layout/NavMenu.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import styled from '@emotion/styled';
44
import { usePrefixedTranslation } from 'hooks';
55
import { useStore } from 'store';
66
import { Badge, HeaderFour } from 'components/base';
7+
import { PUBLIC_URL } from '../../config';
78

89
const Styled = {
910
NavHeader: styled(HeaderFour)`
@@ -52,7 +53,9 @@ const NavItem: React.FC<{
5253
}> = observer(({ page, preview, onClick }) => {
5354
const { l } = usePrefixedTranslation('cmps.layout.NavMenu');
5455
const { router } = useStore();
55-
const className = router.location.pathname === `/${page}` ? 'active' : '';
56+
const className = router.location.pathname.startsWith(`${PUBLIC_URL}/${page}`)
57+
? 'active'
58+
: '';
5659

5760
return (
5861
<Styled.NavItem className={className}>

app/src/components/settings/SettingsPage.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import BalanceSettings from './BalanceSettings';
66
import ExplorerSettings from './ExplorerSettings';
77
import GeneralSettings from './GeneralSettings';
88
import UnitSettings from './UnitSettings';
9+
import { PUBLIC_URL } from '../../config';
910

1011
const Styled = {
1112
Wrapper: styled.div`
@@ -19,10 +20,10 @@ const SettingsPage: React.FC = () => {
1920
return (
2021
<Wrapper>
2122
<Switch>
22-
<Route path="/settings" exact component={GeneralSettings} />
23-
<Route path="/settings/unit" component={UnitSettings} />
24-
<Route path="/settings/balance" component={BalanceSettings} />
25-
<Route path="/settings/explorers" component={ExplorerSettings} />
23+
<Route path={`${PUBLIC_URL}/settings`} exact component={GeneralSettings} />
24+
<Route path={`${PUBLIC_URL}/settings/unit"`} component={UnitSettings} />
25+
<Route path={`${PUBLIC_URL}/settings/balance`} component={BalanceSettings} />
26+
<Route path={`${PUBLIC_URL}/settings/explorers`} component={ExplorerSettings} />
2627
</Switch>
2728
</Wrapper>
2829
);

app/src/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export const IS_PROD = process.env.NODE_ENV === 'production';
77
// flag to check if the app is running in a a test environment
88
export const IS_TEST = process.env.NODE_ENV === 'test';
99

10+
export const PUBLIC_URL = process.env.PUBLIC_URL;
11+
1012
// detect the host currently serving the app files
1113
const { protocol, hostname, port } = window.location;
1214
const host = `${protocol}//${hostname}:${port}`;

app/src/store/store.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
RegisterSidecarView,
3030
RenewAccountView,
3131
} from './views';
32+
import { PUBLIC_URL } from '../config';
3233

3334
/**
3435
* The store used to manage global app state
@@ -125,7 +126,7 @@ export class Store {
125126
// entering a password or from loading the credentials from storage.
126127
// only do this if the auth page is currently being viewed, otherwise
127128
// stay on the current page (ex: history, settings)
128-
if (document.location.pathname === '/') {
129+
if (document.location.pathname === `${PUBLIC_URL}/`) {
129130
runInAction(() => {
130131
this.appView.goToLoop();
131132
});

app/src/store/views/appView.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Big from 'big.js';
55
import { AuthenticationError } from 'util/errors';
66
import { prefixTranslation } from 'util/translate';
77
import { Store } from 'store';
8+
import { PUBLIC_URL } from '../../config';
89

910
const { l } = prefixTranslation('stores.appView');
1011

@@ -28,7 +29,7 @@ export default class AppView {
2829
}
2930

3031
get fullWidth() {
31-
return this._store.router.location.pathname === '/pool';
32+
return this._store.router.location.pathname === `${PUBLIC_URL}/pool`;
3233
}
3334

3435
/** navigate to the specified route */
@@ -40,13 +41,13 @@ export default class AppView {
4041

4142
/** Change to the Auth page */
4243
gotoAuth() {
43-
this.goTo('/');
44+
this.goTo(`${PUBLIC_URL}/`);
4445
this._store.log.info('Go to the Auth page');
4546
}
4647

4748
/** Change to the Loop page */
4849
goToLoop() {
49-
this.goTo('/loop');
50+
this.goTo(`${PUBLIC_URL}/loop`);
5051
this._store.settingsStore.autoCollapseSidebar();
5152
if (!this._store.settingsStore.tourAutoShown) {
5253
this.showTour();
@@ -57,22 +58,22 @@ export default class AppView {
5758

5859
/** Change to the History page */
5960
goToHistory() {
60-
this.goTo('/history');
61+
this.goTo(`${PUBLIC_URL}/history`);
6162
this._store.settingsStore.autoCollapseSidebar();
6263
this._store.log.info('Go to the History page');
6364
}
6465

6566
/** Change to the Pool page */
6667
goToPool() {
67-
this.goTo('/pool');
68+
this.goTo(`${PUBLIC_URL}/pool`);
6869
// always collapse the sidebar to make room for the Pool sidebar
6970
this._store.settingsStore.sidebarVisible = false;
7071
this._store.log.info('Go to the Pool page');
7172
}
7273

7374
/** Change to the Settings page */
7475
goToSettings() {
75-
this.goTo('/settings');
76+
this.goTo(`${PUBLIC_URL}/settings`);
7677
this._store.settingsStore.autoCollapseSidebar();
7778
this._store.log.info('Go to the Settings page');
7879
}
@@ -163,7 +164,7 @@ export default class AppView {
163164
/** sets the selected setting to display */
164165
showSettings(name: SettingName) {
165166
const path = name === '' ? '' : `/${name}`;
166-
this.goTo(`/settings${path}`);
167+
this.goTo(`${PUBLIC_URL}/settings${path}`);
167168
this._store.log.info('Switch to Setting screen', name);
168169
}
169170

0 commit comments

Comments
 (0)