mirror of
https://github.com/ajnart/homarr.git
synced 2026-01-31 11:49:14 +01:00
33 lines
815 B
TypeScript
33 lines
815 B
TypeScript
"use client";
|
|
|
|
import { createTRPCClient, httpLink } from "@trpc/client";
|
|
import { createTRPCReact } from "@trpc/react-query";
|
|
import SuperJSON from "superjson";
|
|
|
|
import type { AppRouter } from ".";
|
|
import { createHeadersCallbackForSource } from "./shared";
|
|
|
|
export const clientApi = createTRPCReact<AppRouter>();
|
|
export const fetchApi = createTRPCClient<AppRouter>({
|
|
links: [
|
|
httpLink({
|
|
url: getTrpcUrl(),
|
|
transformer: SuperJSON,
|
|
headers: createHeadersCallbackForSource("fetch"),
|
|
}),
|
|
],
|
|
});
|
|
|
|
function getBaseUrl() {
|
|
if (typeof window !== "undefined") return window.location.origin;
|
|
return `http://localhost:${process.env.PORT ?? 3000}`;
|
|
}
|
|
|
|
/**
|
|
* Creates the full url for the trpc api endpoint
|
|
* @returns
|
|
*/
|
|
export function getTrpcUrl() {
|
|
return `${getBaseUrl()}/api/trpc`;
|
|
}
|