Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dedicated frontend error page when API_ENDPOINT points to the frontend #404

Merged
merged 2 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion apps/client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import CollaborativeSongs from "./scenes/Collaborative/Affinity/Songs";
import CollaborativeAlbums from "./scenes/Collaborative/Affinity/Albums";
import CollaborativeArtists from "./scenes/Collaborative/Affinity/Artists";
import "./App.css";
import RegistrationsDisabled from "./scenes/RegistrationsDisabled";
import RegistrationsDisabled from "./scenes/Error/RegistrationsDisabled";
import Affinity from "./scenes/Collaborative/Affinity";
import { useTheme } from "./services/theme";
import { selectDarkMode } from "./services/redux/modules/user/selector";
Expand All @@ -29,6 +29,7 @@ import TrackStats from "./scenes/TrackStats";
import LongestSessions from "./scenes/LongestSessions";
import AlbumStats from "./scenes/AlbumStats";
import Benchmarks from "./scenes/Benchmarks";
import ApiEndpointSetToFronted from "./scenes/Error/ApiEndpointSetToFronted";

function App() {
const dark = useSelector(selectDarkMode);
Expand Down Expand Up @@ -82,6 +83,10 @@ function App() {
path="/registrations-disabled"
element={<RegistrationsDisabled />}
/>
<Route
path="/oauth/spotify" // Error page when someone accidentally configures their API_ENDPOINT to point to the frontend instead of the backend
element={<ApiEndpointSetToFronted />}
/>
<Route
path="/top/songs"
element={
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Text from "../../../components/Text";
import s from "../index.module.css";
import { getApiEndpoint } from "../../../services/tools";

export default function ApiEndpointSetToFrontend() {
return (
<div className={s.root}>
<Text element="h1">API Endpoint is not set up correctly</Text>
<Text className={s.explain}>
This request should have reached the backend, but was handled by the
frontend instead.
<p />
This is usually because your &nbsp;<code>API_ENDPOINT</code>&nbsp;
variable points to the frontend instead of the backend.
Please double-check your configuration.
<p />
The current configuration is: <br />
<code>API_ENDPOINT={getApiEndpoint()}</code>
</Text>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "./ApiEndpointSetToFrontend";
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Text from "../../components/Text";
import s from "./index.module.css";
import Text from "../../../components/Text";
import s from "../index.module.css";

export default function RegistrationsDisabled() {
return (
Expand Down
4 changes: 3 additions & 1 deletion apps/client/src/services/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export function getAtLeastImage(images: SpotifyImage[], size: number) {
}

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

export const getSpotifyLogUrl = () => `${getApiEndpoint()}/oauth/spotify`;

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