feat(apps): bootstrap, env, i18n, providers, error pages and session proxy
- env validated with the env lib (NEXT_PUBLIC_API_ORIGIN, API_INTERNAL_ORIGIN,
site URL, support config); .env.example per app
- client bootstrap: API base under /v1, one shared session refresh, error
mapping; server bootstrap: cookie forwarding for server renders
- i18n instance for the server, bound to react-i18next on the client
- root layout, AppProviders, global-error, not-found and a page boundary in
every route group; instrumentation reports uncaught server errors
- proxy.ts refreshes an expired session before rendering
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 17:33:07 +00:00
|
|
|
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';
|
2026-10-07 19:02:58 +00:00
|
|
|
import { SERVER_RESOURCES } from '@lumina/market/server';
|
feat(apps): bootstrap, env, i18n, providers, error pages and session proxy
- env validated with the env lib (NEXT_PUBLIC_API_ORIGIN, API_INTERNAL_ORIGIN,
site URL, support config); .env.example per app
- client bootstrap: API base under /v1, one shared session refresh, error
mapping; server bootstrap: cookie forwarding for server renders
- i18n instance for the server, bound to react-i18next on the client
- root layout, AppProviders, global-error, not-found and a page boundary in
every route group; instrumentation reports uncaught server errors
- proxy.ts refreshes an expired session before rendering
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 17:33:07 +00:00
|
|
|
import { cookies } from 'next/headers';
|
|
|
|
|
|
2026-10-06 17:47:18 +00:00
|
|
|
import {
|
|
|
|
|
API_PROXY_PATH,
|
|
|
|
|
API_VERSION_PATH,
|
|
|
|
|
FORWARDED_COOKIES,
|
|
|
|
|
} from '../constants';
|
feat(apps): bootstrap, env, i18n, providers, error pages and session proxy
- env validated with the env lib (NEXT_PUBLIC_API_ORIGIN, API_INTERNAL_ORIGIN,
site URL, support config); .env.example per app
- client bootstrap: API base under /v1, one shared session refresh, error
mapping; server bootstrap: cookie forwarding for server renders
- i18n instance for the server, bound to react-i18next on the client
- root layout, AppProviders, global-error, not-found and a page boundary in
every route group; instrumentation reports uncaught server errors
- proxy.ts refreshes an expired session before rendering
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 17:33:07 +00:00
|
|
|
import { clientEnv } from '../env';
|
|
|
|
|
import { serverEnv } from '../env/server';
|
2026-10-07 19:02:58 +00:00
|
|
|
import { i18n } from '../i18n';
|
feat(apps): bootstrap, env, i18n, providers, error pages and session proxy
- env validated with the env lib (NEXT_PUBLIC_API_ORIGIN, API_INTERNAL_ORIGIN,
site URL, support config); .env.example per app
- client bootstrap: API base under /v1, one shared session refresh, error
mapping; server bootstrap: cookie forwarding for server renders
- i18n instance for the server, bound to react-i18next on the client
- root layout, AppProviders, global-error, not-found and a page boundary in
every route group; instrumentation reports uncaught server errors
- proxy.ts refreshes an expired session before rendering
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 17:33:07 +00:00
|
|
|
import { ERROR_HANDLER_CONFIG } from './error-reporting';
|
|
|
|
|
|
|
|
|
|
// Fills the server module graph once, before rendering. Idempotent: safe to run again.
|
|
|
|
|
setMarketEnv({
|
2026-10-06 17:47:18 +00:00
|
|
|
apiBaseUrl: API_PROXY_PATH,
|
feat(apps): bootstrap, env, i18n, providers, error pages and session proxy
- env validated with the env lib (NEXT_PUBLIC_API_ORIGIN, API_INTERNAL_ORIGIN,
site URL, support config); .env.example per app
- client bootstrap: API base under /v1, one shared session refresh, error
mapping; server bootstrap: cookie forwarding for server renders
- i18n instance for the server, bound to react-i18next on the client
- root layout, AppProviders, global-error, not-found and a page boundary in
every route group; instrumentation reports uncaught server errors
- proxy.ts refreshes an expired session before rendering
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 17:33:07 +00:00
|
|
|
baleHandle: clientEnv.NEXT_PUBLIC_BALE_HANDLE,
|
|
|
|
|
telegramHandle: clientEnv.NEXT_PUBLIC_TELEGRAM_HANDLE,
|
|
|
|
|
supportHours: clientEnv.NEXT_PUBLIC_SUPPORT_HOURS,
|
|
|
|
|
});
|
refactor(market,apps): drop the session proxy and restore auth in the browser
The server render no longer depends on auth: it reads no session and
forwards only FORWARDED_COOKIES (none today), so every visitor of a URL
gets the same HTML and the Next.js proxy is no longer needed.
- Remove proxy.ts from bull and bear, the app/session module, the
server auth and role guards, and the server caches that read the
viewer's own data. Public caches stay: channel, post, prediction stats.
- Add an auth store (status unknown | guest | member) filled by the
restoreSession action, which reads GET /auth/session once per load
from the AppShell's useSession hook.
- Login and register actions set the store, logout clears it; the
AppShell clears the query cache on auth.logout. No router.refresh.
- Add client AuthGuard (fallback, optional role) and GuestGuard, with
safeReturnPath limiting post-login redirects to same-site paths.
- readOnServer no longer redirects on 401.
- The browser HTTP client refreshes against AUTH_ENDPOINTS.refresh.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 18:28:05 +00:00
|
|
|
// Server requests forward only the allowlisted cookies, never the session: the server render is
|
|
|
|
|
// the same for every visitor, and the browser loads whatever depends on the viewer. Read on each
|
|
|
|
|
// request; nothing per visitor is kept in module state.
|
feat(apps): bootstrap, env, i18n, providers, error pages and session proxy
- env validated with the env lib (NEXT_PUBLIC_API_ORIGIN, API_INTERNAL_ORIGIN,
site URL, support config); .env.example per app
- client bootstrap: API base under /v1, one shared session refresh, error
mapping; server bootstrap: cookie forwarding for server renders
- i18n instance for the server, bound to react-i18next on the client
- root layout, AppProviders, global-error, not-found and a page boundary in
every route group; instrumentation reports uncaught server errors
- proxy.ts refreshes an expired session before rendering
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 17:33:07 +00:00
|
|
|
configureServerHttp({
|
|
|
|
|
baseUrl: `${serverEnv.API_INTERNAL_ORIGIN}${API_VERSION_PATH}`,
|
refactor(market,apps): drop the session proxy and restore auth in the browser
The server render no longer depends on auth: it reads no session and
forwards only FORWARDED_COOKIES (none today), so every visitor of a URL
gets the same HTML and the Next.js proxy is no longer needed.
- Remove proxy.ts from bull and bear, the app/session module, the
server auth and role guards, and the server caches that read the
viewer's own data. Public caches stay: channel, post, prediction stats.
- Add an auth store (status unknown | guest | member) filled by the
restoreSession action, which reads GET /auth/session once per load
from the AppShell's useSession hook.
- Login and register actions set the store, logout clears it; the
AppShell clears the query cache on auth.logout. No router.refresh.
- Add client AuthGuard (fallback, optional role) and GuestGuard, with
safeReturnPath limiting post-login redirects to same-site paths.
- readOnServer no longer redirects on 401.
- The browser HTTP client refreshes against AUTH_ENDPOINTS.refresh.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 18:28:05 +00:00
|
|
|
getCookieHeader: async () =>
|
|
|
|
|
(await cookies())
|
|
|
|
|
.getAll()
|
|
|
|
|
.filter(({ name }) => FORWARDED_COOKIES.has(name))
|
|
|
|
|
.map(({ name, value }) => `${name}=${encodeURIComponent(value)}`)
|
|
|
|
|
.join('; '),
|
feat(apps): bootstrap, env, i18n, providers, error pages and session proxy
- env validated with the env lib (NEXT_PUBLIC_API_ORIGIN, API_INTERNAL_ORIGIN,
site URL, support config); .env.example per app
- client bootstrap: API base under /v1, one shared session refresh, error
mapping; server bootstrap: cookie forwarding for server renders
- i18n instance for the server, bound to react-i18next on the client
- root layout, AppProviders, global-error, not-found and a page boundary in
every route group; instrumentation reports uncaught server errors
- proxy.ts refreshes an expired session before rendering
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 17:33:07 +00:00
|
|
|
});
|
|
|
|
|
http.configure({ mapErrorBody: mapApiErrorBody });
|
|
|
|
|
configureErrorHandler(ERROR_HANDLER_CONFIG);
|
2026-10-07 19:02:58 +00:00
|
|
|
// Namespaces only server components read (the landing) join the server's i18n instance here, so
|
|
|
|
|
// no client bundle carries them. Existing keys are kept, so running this again changes nothing.
|
|
|
|
|
for (const [language, bundles] of Object.entries(SERVER_RESOURCES)) {
|
|
|
|
|
for (const [namespace, bundle] of Object.entries(bundles)) {
|
|
|
|
|
i18n.addResourceBundle(language, namespace, bundle);
|
|
|
|
|
}
|
|
|
|
|
}
|