You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add an environment configuration utility to the generated project templates. This provides type-safe environment variable loading with validation, replacing raw `process.env` access.
Why
Raw `process.env` access is untyped and error-prone — missing variables cause runtime crashes. A typed config utility catches missing/invalid variables at startup with clear error messages.
Acceptance Criteria
Add a `src/config.ts` template to `setup-project.sh`
Use Zod for environment variable validation:
```typescript
import { z } from 'zod';
Description
Add an environment configuration utility to the generated project templates. This provides type-safe environment variable loading with validation, replacing raw `process.env` access.
Why
Raw `process.env` access is untyped and error-prone — missing variables cause runtime crashes. A typed config utility catches missing/invalid variables at startup with clear error messages.
Acceptance Criteria
Add a `src/config.ts` template to `setup-project.sh`
Use Zod for environment variable validation:
```typescript
import { z } from 'zod';
const envSchema = z.object({
NODE_ENV: z.enum(['development', 'production', 'test']).default('development'),
PORT: z.coerce.number().default(3000),
DATABASE_URL: z.string().url(),
JWT_SECRET: z.string().min(32),
LOG_LEVEL: z.enum(['debug', 'info', 'warn', 'error']).default('info'),
});
export const config = envSchema.parse(process.env);
export type Config = z.infer;
```
Import and use `config` in the generated `src/index.ts` instead of raw `process.env`
Provide different defaults for development vs. production
For Cloudflare Workers, adapt to use Hono's `Bindings` pattern instead
CI passes