30 lines
1.2 KiB
TypeScript
30 lines
1.2 KiB
TypeScript
|
|
import 'server-only';
|
||
|
|
|
||
|
|
import { configureErrorHandler } from '@lumina/libs/error-handler';
|
||
|
|
import { http } from '@lumina/libs/http';
|
||
|
|
import { configureServerHttp } from '@lumina/libs/server';
|
||
|
|
import { mapApiErrorBody } from '@lumina/market/app/http';
|
||
|
|
import { setEnv as setMarketEnv } from '@lumina/market/env';
|
||
|
|
import { cookies } from 'next/headers';
|
||
|
|
|
||
|
|
import { API_VERSION_PATH } from '../constants';
|
||
|
|
import { clientEnv } from '../env';
|
||
|
|
import { serverEnv } from '../env/server';
|
||
|
|
import { ERROR_HANDLER_CONFIG } from './error-reporting';
|
||
|
|
|
||
|
|
// Fills the server module graph once, before rendering. Idempotent: safe to run again.
|
||
|
|
setMarketEnv({
|
||
|
|
apiOrigin: clientEnv.NEXT_PUBLIC_API_ORIGIN,
|
||
|
|
baleHandle: clientEnv.NEXT_PUBLIC_BALE_HANDLE,
|
||
|
|
telegramHandle: clientEnv.NEXT_PUBLIC_TELEGRAM_HANDLE,
|
||
|
|
supportHours: clientEnv.NEXT_PUBLIC_SUPPORT_HOURS,
|
||
|
|
});
|
||
|
|
// Each server request forwards its own user's session cookies; nothing per user is kept in module
|
||
|
|
// state. The server never refreshes: proxy.ts already did, before rendering.
|
||
|
|
configureServerHttp({
|
||
|
|
baseUrl: `${serverEnv.API_INTERNAL_ORIGIN}${API_VERSION_PATH}`,
|
||
|
|
getCookieHeader: async () => (await cookies()).toString(),
|
||
|
|
});
|
||
|
|
http.configure({ mapErrorBody: mapApiErrorBody });
|
||
|
|
configureErrorHandler(ERROR_HANDLER_CONFIG);
|