🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
change host url
Bill Yang403096127abe
diff --git a/client/src/hooks/api.ts b/client/src/hooks/api.tsindex 6852705ec..4f51774b2 100644--- a/client/src/hooks/api.ts+++ b/client/src/hooks/api.ts@@ -5,6 +5,7 @@ import {} from "@tanstack/react-query";import { useStore } from "../lib/store";import { authedFetch, getStartAndEndDate } from "./utils";+import { BACKEND_URL } from "../lib/const";export type APIResponse<T> = {data: T;@@ -16,9 +17,9 @@ export function useGetLiveUsercount() {return useQuery({queryKey: ["live-user-count", site],queryFn: () =>- authedFetch(- `${process.env.NEXT_PUBLIC_BACKEND_URL}/live-user-count/${site}`- ).then((res) => res.json()),+ authedFetch(`${BACKEND_URL}/live-user-count/${site}`).then((res) =>+ res.json()+ ),});}@@ -37,7 +38,7 @@ export function useGenericQuery<T>(queryFn: () => {const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;return authedFetch(- `${process.env.NEXT_PUBLIC_BACKEND_URL}/${endpoint}?startDate=${startDate}&endDate=${endDate}&timezone=${timezone}&site=${site}`+ `${BACKEND_URL}/${endpoint}?startDate=${startDate}&endDate=${endDate}&timezone=${timezone}&site=${site}`).then((res) => res.json());},staleTime: Infinity,@@ -123,7 +124,7 @@ export function useGetPageviews(queryFn: () => {const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;return authedFetch(- `${process.env.NEXT_PUBLIC_BACKEND_URL}/pageviews?startDate=${startDate}&endDate=${endDate}&timezone=${timezone}&bucket=${bucket}&site=${site}`+ `${BACKEND_URL}/pageviews?startDate=${startDate}&endDate=${endDate}&timezone=${timezone}&bucket=${bucket}&site=${site}`).then((res) => res.json());},placeholderData: keepPreviousData,@@ -158,7 +159,7 @@ export function useGetSites() {}export function addSite(domain: string, name: string) {- return authedFetch(`${process.env.NEXT_PUBLIC_BACKEND_URL}/add-site`, {+ return authedFetch(`${BACKEND_URL}/add-site`, {method: "POST",body: JSON.stringify({domain,@@ -168,10 +169,7 @@ export function addSite(domain: string, name: string) {}export function deleteSite(siteId: string) {- return authedFetch(- `${process.env.NEXT_PUBLIC_BACKEND_URL}/delete-site/${siteId}`,- {- method: "POST",- }- );+ return authedFetch(`${BACKEND_URL}/delete-site/${siteId}`, {+ method: "POST",+ });}diff --git a/client/src/lib/auth.ts b/client/src/lib/auth.tsindex 73a84142e..0cf925fff 100644--- a/client/src/lib/auth.ts+++ b/client/src/lib/auth.ts@@ -1,9 +1,9 @@import { createAuthClient } from "better-auth/react";import { usernameClient } from "better-auth/client/plugins";+import { BACKEND_URL } from "./const";export const authClient = createAuthClient({- // baseURL: process.env.NEXT_PUBLIC_BACKEND_URL,- baseURL: process.env.NEXT_PUBLIC_BACKEND_URL?.replace("/api", ""), // the base url of your auth server+ baseURL: BACKEND_URL,plugins: [usernameClient()],fetchOptions: {credentials: "include",diff --git a/client/src/lib/const.ts b/client/src/lib/const.tsnew file mode 100644index 000000000..e760911d7--- /dev/null+++ b/client/src/lib/const.ts@@ -0,0 +1,4 @@+export const BACKEND_URL =+ process.env.NEXT_PUBLIC_BACKEND_URL === "http://localhost:3001"+ ? "http://localhost:3001"+ : `${process.env.NEXT_PUBLIC_BACKEND_URL}/api`;