Basic Architecture of Sport Web
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import { createApiClient } from '@sport/api-client';
|
||||
|
||||
import { clientEnv, getServerEnv } from './env';
|
||||
|
||||
/**
|
||||
* Two clients, because the two runtimes have different needs:
|
||||
*
|
||||
* - `serverApi` runs inside React Server Components and route handlers. In
|
||||
* Docker it reaches the API container over the internal network, skipping
|
||||
* the public hostname and TLS entirely.
|
||||
* - `browserApi` runs in the browser, hits the public API and carries the
|
||||
* access token.
|
||||
*
|
||||
* Both are the same typed client from @sport/api-client. No component anywhere
|
||||
* calls `fetch` against the API directly.
|
||||
*/
|
||||
export function getServerApi() {
|
||||
return createApiClient({
|
||||
baseUrl: getServerEnv().API_INTERNAL_URL,
|
||||
// Server-side requests are anonymous by default. Authenticated server
|
||||
// fetches pass the token explicitly, per request, once auth lands.
|
||||
});
|
||||
}
|
||||
|
||||
export const browserApi = createApiClient({
|
||||
baseUrl: clientEnv.NEXT_PUBLIC_API_URL,
|
||||
getAccessToken: () => null, // wired to the auth store in the auth milestone
|
||||
});
|
||||
Reference in New Issue
Block a user