fix(api,web): env startup validation, QueryClient defaults, warn on missing REDIS_URL
- Throw at startup in production if REDIS_URL/DATABASE_URL/NEXTAUTH_SECRET missing - Warn in development when REDIS_URL falls back to localhost - QueryClient: add gcTime, disable refetchOnWindowFocus, skip retry on 4xx Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,11 @@
|
||||
export async function register() {
|
||||
// Validate required env vars at startup — throws immediately in production
|
||||
// if REDIS_URL, DATABASE_URL, or NEXTAUTH_SECRET are missing.
|
||||
if (process.env.NEXT_RUNTIME === "nodejs") {
|
||||
const { assertProductionEnv } = await import("@capakraken/api");
|
||||
assertProductionEnv();
|
||||
}
|
||||
|
||||
// Only load Sentry in production — the worker.js crash in dev mode
|
||||
// (vendor-chunks/lib/worker.js MODULE_NOT_FOUND) makes the dev server unstable
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
|
||||
@@ -50,12 +50,18 @@ export function TRPCProvider({ children }: { children: React.ReactNode }) {
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
staleTime: 60_000, // 60 seconds — reduces refetches on navigation
|
||||
gcTime: 5 * 60_000, // 5 minutes — keep inactive queries in memory
|
||||
refetchOnWindowFocus: false,
|
||||
refetchOnReconnect: false,
|
||||
retry: (failureCount, error) => {
|
||||
// Never retry UNAUTHORIZED — redirect immediately instead
|
||||
if (isUnauthorizedTrpcError(error)) return false;
|
||||
return failureCount < 1;
|
||||
// Don't retry on 4xx errors (auth, not found, bad input)
|
||||
if (error instanceof TRPCClientError) {
|
||||
const code = error.data?.httpStatus as number | undefined;
|
||||
if (code !== undefined && code >= 400 && code < 500) return false;
|
||||
}
|
||||
return failureCount < 2;
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user