-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_trpcServer.ts
31 lines (29 loc) · 1.01 KB
/
_trpcServer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import "server-only";
import { createTRPCProxyClient, httpBatchLink, loggerLink } from "@trpc/client";
import { cache } from "react";
import superjson from "superjson";
import type { AppRouter } from "../../server";
// Create a request-scoped singleton instance of TrpcProxyClient.
// This ensures that data is not shared between different users and requests,
// while still only creating the TrpcProxyClient once per request.
//
// See: https://beta.nextjs.org/docs/data-fetching/caching#per-request-caching
export const getServerTrpcClient = cache(() =>
createTRPCProxyClient<AppRouter>({
links: [
loggerLink({
enabled: (opts) =>
process.env.NODE_ENV === "development" && opts.direction === "down",
}),
httpBatchLink({
url: `${process.env.NEXT_PUBLIC_API_HOST}/api`,
headers: async () => {
return {
'Access-Control-Allow-Origin': '*', // Required for CORS support to work
}
}
})
],
transformer: superjson,
})
);