Skip to content

Commit 280add7

Browse files
committed
Prepare for reverse proxy usage #125
Not working correctly yet but no BC for regular, non suburl, usage
1 parent b34abca commit 280add7

File tree

10 files changed

+24
-11
lines changed

10 files changed

+24
-11
lines changed

src/backend/ioc.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ const createRoot = (options?: RootOptions) => {
7575
sources: () => new ScrobbleSources(items.sourceEmitter, localUrl, items.configDir),
7676
notifiers: () => new Notifiers(items.notifierEmitter, items.clientEmitter, items.sourceEmitter),
7777
localUrl,
78-
hasDefinedBaseUrl: baseUrl !== undefined
78+
hasDefinedBaseUrl: baseUrl !== undefined,
79+
isSubPath: u.pathname !== '/' && u.pathname.length > 0
7980
}
8081
});
8182
}

src/backend/server/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ export const initServer = async (parentLogger: Logger, initialOutput: LogInfo[]
7171
}
7272
}
7373

74+
if(process.env.USE_HASH_ROUTER === undefined) {
75+
process.env.USE_HASH_ROUTER = root.get('isSubPath');
76+
}
7477
ViteExpress.config({mode: isProd ? 'production' : 'development'});
7578
try {
7679
ViteExpress.listen(app, port, () => {

src/client/App.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React from 'react';
2-
import logo from './logo.svg';
3-
import * as ReactDOM from "react-dom/client";
42
import {
53
createBrowserRouter,
4+
createHashRouter, RouteObject,
65
RouterProvider, useLocation,
76
} from "react-router-dom";
87
import {connect, ConnectedProps, Provider} from 'react-redux'
@@ -25,7 +24,7 @@ function NoMatch() {
2524
);
2625
}
2726

28-
const router = createBrowserRouter([
27+
const routes: RouteObject[] = [
2928
{
3029
path: "/",
3130
element: <Dashboard />,
@@ -46,7 +45,14 @@ const router = createBrowserRouter([
4645
path: "*",
4746
element: <NoMatch/>
4847
}
49-
]);
48+
];
49+
50+
const genRouter = () => {
51+
const useHashRouter = __USE_HASH_ROUTER__ === 'true';
52+
return useHashRouter ? createHashRouter(routes) : createBrowserRouter(routes);
53+
}
54+
55+
const router = genRouter();
5056

5157
const mapDispatchToProps = (dispatch) => {
5258
return {

src/client/deadLetter/deadLetterDucks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {ApiEventPayload, clientUpdate} from "../status/ducks";
66
type DeadResponse = DeadLetterScrobble<JsonPlayObject, string>[];
77
export const deadApi = createApi({
88
reducerPath: 'deadApi',
9-
baseQuery: fetchBaseQuery({baseUrl: '/api/'}),
9+
baseQuery: fetchBaseQuery({baseUrl: './api/'}),
1010
tagTypes: ['DeadLetters'],
1111
endpoints: (builder) => ({
1212
getDead: builder.query<DeadResponse, { name: string, type: string }>({

src/client/logs/logsApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {LogInfoJson, LogOutputConfig} from "../../core/Atomic";
33

44
export const logsApi = createApi({
55
reducerPath: 'logsApi',
6-
baseQuery: fetchBaseQuery({ baseUrl: '/api/' }),
6+
baseQuery: fetchBaseQuery({ baseUrl: './api/' }),
77
endpoints: (builder) => ({
88
getLogs: builder.query<{ data: LogInfoJson[], settings: LogOutputConfig }, undefined>({
99
query: () => `logs`,

src/client/recent/recentDucks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {JsonPlayObject} from "../../core/Atomic";
44
type RecentResponse = (JsonPlayObject & { index: number })[];
55
export const recentApi = createApi({
66
reducerPath: 'recentApi',
7-
baseQuery: fetchBaseQuery({ baseUrl: '/api/' }),
7+
baseQuery: fetchBaseQuery({ baseUrl: './api/' }),
88
endpoints: (builder) => ({
99
getRecent: builder.query<RecentResponse, {name: string, type: string}>({
1010
query: (params) => `recent?name=${params.name}&type=${params.type}`,

src/client/scrobbled/scrobbledDucks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {JsonPlayObject} from "../../core/Atomic";
44
type ScrobbledResponse = (JsonPlayObject & { index: number })[];
55
export const scrobbledApi = createApi({
66
reducerPath: 'scrobbledApi',
7-
baseQuery: fetchBaseQuery({ baseUrl: '/api/' }),
7+
baseQuery: fetchBaseQuery({ baseUrl: './api/' }),
88
endpoints: (builder) => ({
99
getRecent: builder.query<ScrobbledResponse, {name: string, type: string}>({
1010
query: (params) => `scrobbled?name=${params.name}&type=${params.type}`,

src/client/status/statusApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {ClientStatusData, SourceStatusData} from "../../core/Atomic";
33

44
export const statusApi = createApi({
55
reducerPath: 'statusApi',
6-
baseQuery: fetchBaseQuery({ baseUrl: '/api/' }),
6+
baseQuery: fetchBaseQuery({ baseUrl: './api/' }),
77
endpoints: (builder) => ({
88
getStatus: builder.query<{ sources: SourceStatusData[], clients: ClientStatusData[] }, undefined>({
99
query: () => `status`,

src/client/vite-env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/// <reference types="vite/client" />
22
declare const __APP_VERSION__: string
3+
declare const __USE_HASH_ROUTER__: bool

vite.config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ import react from '@vitejs/plugin-react';
33

44
export default defineConfig(() => {
55
return {
6+
base: (process.env.BASE_URL ?? '/'),
67
plugins: [react()],
78
build: {
89
sourcemap: true
910
},
1011
define: {
11-
"__APP_VERSION__": JSON.stringify((process.env.APP_VERSION ?? 'Unknown').toString())
12+
"__APP_VERSION__": JSON.stringify((process.env.APP_VERSION ?? 'Unknown').toString()),
13+
"__USE_HASH_ROUTER__": JSON.stringify((process.env.USE_HASH_ROUTER ?? false))
1214
}
1315
};
1416
});

0 commit comments

Comments
 (0)