aboutsummaryrefslogtreecommitdiffstats
path: root/src/web
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-05-07 14:27:53 -0500
committerGitHub <noreply@github.com>2022-05-07 14:27:53 -0500
commit6ac44e4540e5b0bf42f99563b47317add8d22aff (patch)
tree3638bc7683b68b0304c2a7ad32c3c9316b123acf /src/web
parent09adf4655f43ab6abeba1d1ac219df94d70c634c (diff)
parent2391114fbcadba7378451c8a066fb466269fdb13 (diff)
downloadslskd-6ac44e4540e5b0bf42f99563b47317add8d22aff.tar.gz
Merge pull request #452 from slskd/routes
Fix UI routing issues
Diffstat (limited to 'src/web')
-rw-r--r--src/web/src/components/App.js30
-rw-r--r--src/web/src/config.js10
-rw-r--r--src/web/src/lib/api.js4
-rw-r--r--src/web/src/lib/application.js4
-rw-r--r--src/web/src/lib/hubFactory.js6
5 files changed, 24 insertions, 30 deletions
diff --git a/src/web/src/components/App.js b/src/web/src/components/App.js
index 19ea8d37..09f3f742 100644
--- a/src/web/src/components/App.js
+++ b/src/web/src/components/App.js
@@ -2,8 +2,8 @@ import React, { Component } from 'react';
import { Route, Link, Switch, Redirect } from "react-router-dom";
import * as session from '../lib/session';
-import * as application from '../lib/application';
import { connect, disconnect } from '../lib/server';
+import { urlBase } from '../config';
import { createApplicationHubConnection } from '../lib/hubFactory';
@@ -39,7 +39,6 @@ const initialState = {
initialized: false,
error: false,
retriesExhausted: false,
- urlBase: '',
};
class App extends Component {
@@ -52,12 +51,7 @@ class App extends Component {
init = async () => {
this.setState({ initialized: false }, async () => {
try {
- const [urlBase, securityEnabled] = await Promise.all([
- application.getUrlBase(),
- session.getSecurityEnabled()]
- );
-
- this.setState({ urlBase });
+ const securityEnabled = await session.getSecurityEnabled();
if (!securityEnabled) {
console.debug('application security is not enabled, per api call')
@@ -116,7 +110,7 @@ class App extends Component {
};
render = () => {
- const { login, applicationState = {}, applicationOptions = {}, error, initialized, retriesExhausted, urlBase = '' } = this.state;
+ const { login, applicationState = {}, applicationOptions = {}, error, initialized, retriesExhausted } = this.state;
const { version = {}, server } = applicationState;
const { isUpdateAvailable, current, latest } = version;
@@ -157,7 +151,7 @@ class App extends Component {
{version.isCanary && <Menu.Item>
<Icon name='flask' color='yellow'/>Canary
</Menu.Item>}
- <Link to={`${urlBase}`}>
+ <Link to={`${urlBase}/searches`}>
<Menu.Item>
<Icon name='search'/>Search
</Menu.Item>
@@ -249,14 +243,14 @@ class App extends Component {
</Sidebar>
<Sidebar.Pusher className='app-content'>
<Switch>
- <Route path='*/searches' render={(props) => this.withTokenCheck(<Search {...props}/>)}/>
- <Route path='*/browse' render={(props) => this.withTokenCheck(<Browse {...props}/>)}/>
- <Route path='*/users' render={(props) => this.withTokenCheck(<Users {...props}/>)}/>
- <Route path='*/chat' render={(props) => this.withTokenCheck(<Chat {...props}/>)}/>
- <Route path='*/rooms' render={(props) => this.withTokenCheck(<Rooms {...props}/>)}/>
- <Route path='*/uploads' render={(props) => this.withTokenCheck(<Transfers {...props} direction='upload'/>)}/>
- <Route path='*/downloads' render={(props) => this.withTokenCheck(<Transfers {...props} direction='download'/>)}/>
- <Route path='*/system/:tab?' render={(props) => this.withTokenCheck(<System state={applicationState} options={applicationOptions}/>)}/>
+ <Route path={`${urlBase}/searches`} render={(props) => this.withTokenCheck(<Search {...props}/>)}/>
+ <Route path={`${urlBase}/browse`} render={(props) => this.withTokenCheck(<Browse {...props}/>)}/>
+ <Route path={`${urlBase}/users`} render={(props) => this.withTokenCheck(<Users {...props}/>)}/>
+ <Route path={`${urlBase}/chat`} render={(props) => this.withTokenCheck(<Chat {...props}/>)}/>
+ <Route path={`${urlBase}/rooms`} render={(props) => this.withTokenCheck(<Rooms {...props}/>)}/>
+ <Route path={`${urlBase}/uploads`} render={(props) => this.withTokenCheck(<Transfers {...props} direction='upload'/>)}/>
+ <Route path={`${urlBase}/downloads`} render={(props) => this.withTokenCheck(<Transfers {...props} direction='download'/>)}/>
+ <Route path={`${urlBase}/system/:tab?`} render={(props) => this.withTokenCheck(<System {...props} state={applicationState} options={applicationOptions}/>)}/>
<Redirect from='*' to={`${urlBase}/searches`}/>
</Switch>
</Sidebar.Pusher>
diff --git a/src/web/src/config.js b/src/web/src/config.js
index ea71e9dd..6f899564 100644
--- a/src/web/src/config.js
+++ b/src/web/src/config.js
@@ -1,5 +1,7 @@
-const rootUrl = process.env.NODE_ENV === 'production' ? '' : 'http://localhost:5000/';
-const baseUrl = `${rootUrl}api/v0`;
+const urlBase = (window.urlBase === '/' ? '' : window.urlBase) || '';
+const rootUrl = process.env.NODE_ENV === 'production' ? urlBase : `http://localhost:5000/${urlBase}`;
+const apiBaseUrl = `${rootUrl}/api/v0`;
+const hubBaseUrl = `${rootUrl}/hub`;
const tokenKey = 'slskd-token';
const tokenPassthroughValue = 'n/a';
const activeChatKey = 'slskd-active-chat';
@@ -7,8 +9,10 @@ const activeRoomKey = 'slskd-active-room';
const activeUserInfoKey = 'slskd-active-user';
export {
+ urlBase,
rootUrl,
- baseUrl,
+ apiBaseUrl,
+ hubBaseUrl,
tokenKey,
tokenPassthroughValue,
activeChatKey,
diff --git a/src/web/src/lib/api.js b/src/web/src/lib/api.js
index 73e75373..0e7d8050 100644
--- a/src/web/src/lib/api.js
+++ b/src/web/src/lib/api.js
@@ -1,8 +1,8 @@
import axios from 'axios';
-import { baseUrl } from '../config';
+import { apiBaseUrl } from '../config';
import * as session from './session';
-axios.defaults.baseURL = baseUrl;
+axios.defaults.baseURL = apiBaseUrl;
const api = axios.create({
withCredentials: true
diff --git a/src/web/src/lib/application.js b/src/web/src/lib/application.js
index da5bbef5..0c8b8319 100644
--- a/src/web/src/lib/application.js
+++ b/src/web/src/lib/application.js
@@ -4,10 +4,6 @@ export const getState = async () => {
return (await api.get('/application')).data;
};
-export const getUrlBase = async () => {
- return (await api.get('/application/urlbase')).data;
-}
-
export const restart = async () => {
return api.put('/application');
};
diff --git a/src/web/src/lib/hubFactory.js b/src/web/src/lib/hubFactory.js
index a64c5c40..246e9d03 100644
--- a/src/web/src/lib/hubFactory.js
+++ b/src/web/src/lib/hubFactory.js
@@ -4,7 +4,7 @@ import {
LogLevel
} from '@microsoft/signalr'
-import { rootUrl } from '../config';
+import { hubBaseUrl } from '../config';
import * as session from '../lib/session';
export const createHubConnection = ({ url }) =>
@@ -18,6 +18,6 @@ export const createHubConnection = ({ url }) =>
.configureLogging(LogLevel.Warning)
.build();
-export const createApplicationHubConnection = () => createHubConnection({ url: `${rootUrl}hub/application` });
+export const createApplicationHubConnection = () => createHubConnection({ url: `${hubBaseUrl}/application` });
-export const createLogsHubConnection = () => createHubConnection({ url: `${rootUrl}hub/logs` }); \ No newline at end of file
+export const createLogsHubConnection = () => createHubConnection({ url: `${hubBaseUrl}/logs` }); \ No newline at end of file