diff --git a/src/env.ts b/src/env.ts index 4983a6c..3105868 100644 --- a/src/env.ts +++ b/src/env.ts @@ -4,11 +4,13 @@ import { z } from 'zod' export const env = createEnv({ server: { DATABASE_URL: z.url({ protocol: /^mysql$/ }), + ENABLE_API_DOCS: z.stringbool().default(false), LOG_DB: z.stringbool().default(false), LOG_FORMAT: z.enum(['pretty', 'json']).optional(), LOG_LEVEL: z.enum(['trace', 'debug', 'info', 'warning', 'error', 'fatal']).default('info'), SOH_PREDICTION_API_BASE_URL: z.url({ protocol: /^https?$/ }), SOH_PREDICTION_CACHE_TTL_SECONDS: z.coerce.number().int().positive().default(86_400), + SOH_PREDICTION_NEGATIVE_CACHE_TTL_SECONDS: z.coerce.number().int().positive().default(300), SOH_PREDICTION_TIMEOUT_MS: z.coerce.number().int().positive().default(10_000), }, clientPrefix: 'VITE_', diff --git a/src/routes/api/$.ts b/src/routes/api/$.ts index a81858b..5f5a3a0 100644 --- a/src/routes/api/$.ts +++ b/src/routes/api/$.ts @@ -4,24 +4,27 @@ import { onError } from '@orpc/server' import { ZodToJsonSchemaConverter } from '@orpc/zod/zod4' import { createFileRoute } from '@tanstack/react-router' import { name, version } from '#package' +import { env } from '@/env' import { handleValidationError, logError } from '@/server/api/interceptors' import { router } from '@/server/api/routers' const handler = new OpenAPIHandler(router, { - plugins: [ - new OpenAPIReferencePlugin({ - docsProvider: 'scalar', - schemaConverters: [new ZodToJsonSchemaConverter()], - specGenerateOptions: { - info: { - title: name, - version, - }, - }, - docsPath: '/docs', - specPath: '/spec.json', - }), - ], + plugins: env.ENABLE_API_DOCS + ? [ + new OpenAPIReferencePlugin({ + docsProvider: 'scalar', + schemaConverters: [new ZodToJsonSchemaConverter()], + specGenerateOptions: { + info: { + title: name, + version, + }, + }, + docsPath: '/docs', + specPath: '/spec.json', + }), + ] + : [], interceptors: [onError(logError)], clientInterceptors: [onError(handleValidationError)], })