UNPKG

@envkit/nextjs

Version:

Environment variable management for Next.js applications

61 lines (60 loc) 1.86 kB
import { NextRequest, NextResponse } from 'next/server'; /** * Configuration for a specific environment */ export interface EnvConfig { /** * Required environment variables for this environment */ requiredVars?: string[]; /** * Target .env file for this environment * @default '.env.local' */ targetEnvFile?: string; } /** * Options for the EnvKit API handler */ export interface EnvApiHandlerOptions { /** * Allow access in production environment * @default false */ allowInProduction?: boolean; /** * The directory to look for .env files * @default process.cwd() */ envDir?: string; /** * The .env file names to look for when loading variables * @default ['.env.local', '.env.development.local', '.env.development', '.env'] */ envFiles?: string[]; /** * Callback function to run after environment variables are updated */ onUpdate?: (updatedVars: Record<string, string>) => Promise<void>; /** * Required environment variables (legacy approach) * @deprecated Use environments object instead */ requiredVars?: string[]; /** * Environment-specific configurations * Keys are environment names (e.g., 'development', 'production') * Values are environment-specific configurations */ environments?: Record<string, EnvConfig>; } export type CreateEnvApiHandlerType = (options?: EnvApiHandlerOptions) => { statusHandler: (request: NextRequest) => Promise<NextResponse>; updateHandler: (request: NextRequest) => Promise<NextResponse>; }; /** * Creates an API handler factory for Next.js * This allows easy setup of the API routes for EnvKit in Next.js applications */ export declare const createEnvApiHandler: CreateEnvApiHandlerType; export default createEnvApiHandler;