Skip to content

Commit

Permalink
feat(*): avoid extra DNS lookup, add note
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnisDa committed Jul 17, 2024
1 parent 5d807e9 commit 5fc4404
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion apps/frontend/app/lib/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export const useUserMetadataDetails = (metadataId?: string | null) => {
return useQuery(getUserMetadataDetailsQuery(metadataId));
};

const useDashboardLayoutData = () => {
export const useDashboardLayoutData = () => {
const loaderData =
useRouteLoaderData<typeof dashboardLoader>("routes/_dashboard");
return loaderData;
Expand Down
3 changes: 2 additions & 1 deletion apps/frontend/app/lib/utilities.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import {
toastKey,
} from "~/lib/generals";

export const API_URL = process.env.API_URL || "http://localhost:8000/backend";
export const API_URL = process.env.API_URL || "http://127.0.0.1:8000/backend";

class AuthenticatedGraphQLClient extends GraphQLClient {
async authenticatedRequest<T, V extends Variables = Variables>(
Expand Down Expand Up @@ -130,6 +130,7 @@ const expectedServerVariables = z.object({
FRONTEND_OIDC_BUTTON_LABEL: z
.string()
.default("Continue with OpenID Connect"),
FRONTEND_DASHBOARD_MESSAGE: z.string().optional(),
});

/**
Expand Down
9 changes: 9 additions & 0 deletions apps/frontend/app/routes/_dashboard._index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { $path } from "@ignisda/remix-routes";
import {
Alert,
Box,
Center,
Container,
Expand Down Expand Up @@ -28,6 +29,7 @@ import { humanizeDuration, isNumber } from "@ryot/ts-utils";
import {
IconBarbell,
IconFriends,
IconInfoCircle,
IconScaleOutline,
IconServer,
} from "@tabler/icons-react";
Expand All @@ -42,6 +44,7 @@ import {
} from "~/components/media";
import { dayjsLib, getLot, getMetadataIcon } from "~/lib/generals";
import {
useDashboardLayoutData,
useGetMantineColor,
useUserPreferences,
useUserUnitSystem,
Expand Down Expand Up @@ -108,11 +111,17 @@ export default function Page() {
const userPreferences = useUserPreferences();
const unitSystem = useUserUnitSystem();
const theme = useMantineTheme();
const dashboardLayoutData = useDashboardLayoutData();
const latestUserSummary = loaderData.latestUserSummary.data;

return (
<Container>
<Stack gap={32}>
{dashboardLayoutData.envData.FRONTEND_DASHBOARD_MESSAGE ? (
<Alert variant="default" icon={<IconInfoCircle />}>
{dashboardLayoutData.envData.FRONTEND_DASHBOARD_MESSAGE}
</Alert>
) : null}
{userPreferences.general.dashboard.map((de) =>
match([de.section, de.hidden])
.with([DashboardElementLot.Upcoming, false], () =>
Expand Down
11 changes: 8 additions & 3 deletions apps/frontend/app/routes/_dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,21 @@ export const loader = unstable_defineLoader(async ({ request }) => {

export function ErrorBoundary() {
const error = useRouteError() as Error;
const message = isRouteErrorResponse(error)
? error.data.message
: error.message;

return (
<Container size="sm" py={{ base: 100, md: 200 }}>
<Stack p={{ base: "sm", md: "xl" }}>
<Text c="red" fz={{ base: 30, md: 40 }}>
We encountered an error
</Text>
<Code mah={100} c="pink">
{isRouteErrorResponse(error) ? error.data.message : error.message}
</Code>
{message ? (
<Code mah={100} c="pink">
{message}
</Code>
) : null}
<Group wrap="nowrap">
<Button
fullWidth
Expand Down
4 changes: 1 addition & 3 deletions apps/frontend/app/routes/auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ export const loader = unstable_defineLoader(async ({ request }) => {
closeAfter: dayjsLib.duration(10, "second").asMilliseconds(),
},
);
throw await redirectWithToast($path("/"), {
message: "You were already logged in",
});
throw redirect($path("/"));
}
const [enabledFeatures, { coreDetails }] = await Promise.all([
getCoreEnabledFeatures(),
Expand Down
6 changes: 3 additions & 3 deletions ci/Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
:{$PORT:8000} {
handle_path /_i/* {
rewrite * /webhooks/integrations{path}
reverse_proxy localhost:5000
reverse_proxy 127.0.0.1:5000
}
handle_path /backend* {
reverse_proxy localhost:5000
reverse_proxy 127.0.0.1:5000
}
handle /health {
header Content-Type text/plain
Expand All @@ -19,5 +19,5 @@
{{ httpInclude "/backend/config" }}
TXT
}
reverse_proxy localhost:3000
reverse_proxy 127.0.0.1:3000
}
4 changes: 4 additions & 0 deletions docs/includes/backend-config-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ file_storage:

# Settings related to frontend storage.
frontend:
# A message to be displayed on the dashboard.
# @envvar FRONTEND_DASHBOARD_MESSAGE
dashboard_message: ""

# The button label for OIDC authentication.
# @envvar FRONTEND_OIDC_BUTTON_LABEL
oidc_button_label: "Continue with OpenID Connect"
Expand Down
2 changes: 2 additions & 0 deletions libs/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ pub struct FrontendConfig {
/// The button label for OIDC authentication.
#[setting(default = "Continue with OpenID Connect")]
pub oidc_button_label: String,
/// A message to be displayed on the dashboard.
pub dashboard_message: String,
/// Settings related to Umami analytics.
#[setting(nested)]
pub umami: FrontendUmamiConfig,
Expand Down

0 comments on commit 5fc4404

Please sign in to comment.