Skip to content

Commit 17b24b4

Browse files
authored
Merge pull request #404 from RagingCactus/frontend-error-pages
Add dedicated frontend error page when API_ENDPOINT points to the frontend
2 parents bb81bbd + 598a580 commit 17b24b4

File tree

7 files changed

+34
-4
lines changed

7 files changed

+34
-4
lines changed

apps/client/src/App.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import CollaborativeSongs from "./scenes/Collaborative/Affinity/Songs";
2020
import CollaborativeAlbums from "./scenes/Collaborative/Affinity/Albums";
2121
import CollaborativeArtists from "./scenes/Collaborative/Affinity/Artists";
2222
import "./App.css";
23-
import RegistrationsDisabled from "./scenes/RegistrationsDisabled";
23+
import RegistrationsDisabled from "./scenes/Error/RegistrationsDisabled";
2424
import Affinity from "./scenes/Collaborative/Affinity";
2525
import { useTheme } from "./services/theme";
2626
import { selectDarkMode } from "./services/redux/modules/user/selector";
@@ -29,6 +29,7 @@ import TrackStats from "./scenes/TrackStats";
2929
import LongestSessions from "./scenes/LongestSessions";
3030
import AlbumStats from "./scenes/AlbumStats";
3131
import Benchmarks from "./scenes/Benchmarks";
32+
import ApiEndpointSetToFronted from "./scenes/Error/ApiEndpointSetToFronted";
3233

3334
function App() {
3435
const dark = useSelector(selectDarkMode);
@@ -82,6 +83,10 @@ function App() {
8283
path="/registrations-disabled"
8384
element={<RegistrationsDisabled />}
8485
/>
86+
<Route
87+
path="/oauth/spotify" // Error page when someone accidentally configures their API_ENDPOINT to point to the frontend instead of the backend
88+
element={<ApiEndpointSetToFronted />}
89+
/>
8590
<Route
8691
path="/top/songs"
8792
element={
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import Text from "../../../components/Text";
2+
import s from "../index.module.css";
3+
import { getApiEndpoint } from "../../../services/tools";
4+
5+
export default function ApiEndpointSetToFrontend() {
6+
return (
7+
<div className={s.root}>
8+
<Text element="h1">API Endpoint is not set up correctly</Text>
9+
<Text className={s.explain}>
10+
This request should have reached the backend, but was handled by the
11+
frontend instead.
12+
<p />
13+
This is usually because your &nbsp;<code>API_ENDPOINT</code>&nbsp;
14+
variable points to the frontend instead of the backend.
15+
Please double-check your configuration.
16+
<p />
17+
The current configuration is: <br />
18+
<code>API_ENDPOINT={getApiEndpoint()}</code>
19+
</Text>
20+
</div>
21+
);
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from "./ApiEndpointSetToFrontend";

apps/client/src/scenes/RegistrationsDisabled/RegistrationsDisabled.tsx renamed to apps/client/src/scenes/Error/RegistrationsDisabled/RegistrationsDisabled.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import Text from "../../components/Text";
2-
import s from "./index.module.css";
1+
import Text from "../../../components/Text";
2+
import s from "../index.module.css";
33

44
export default function RegistrationsDisabled() {
55
return (

apps/client/src/services/tools.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ export function getAtLeastImage(images: SpotifyImage[], size: number) {
1919
}
2020

2121
// @ts-ignore
22-
export const getSpotifyLogUrl = () => `${window.API_ENDPOINT}/oauth/spotify`;
22+
export const getApiEndpoint = () => window.API_ENDPOINT as string;
23+
24+
export const getSpotifyLogUrl = () => `${getApiEndpoint()}/oauth/spotify`;
2325

2426
export const compact = <T>(arr: (T | undefined)[]): T[] =>
2527
arr.filter(a => a != null) as T[];

0 commit comments

Comments
 (0)