strapi.config.ts file controls how strapi2front connects to your Strapi backend and generates code. Created by strapi2front init, it’s validated with Zod for type safety.
Configuration File
The
defineConfig helper provides TypeScript autocomplete and validation.Connection Options
Strapi backend URL. Must be a valid URL.Example:
"http://localhost:1337" or "https://api.example.com"Typically loaded from environment:API token for syncing schema from Strapi. Optional but recommended.Required permissions:
content-type-builder.getContentTypescontent-type-builder.getComponentsi18n.listLocales
API prefix used in your Strapi configuration. Change if you customized Strapi’s REST API prefix.Example:
"/api/v1" or "/custom-api"Strapi Version
Strapi major version. Affects schema parsing and type generation.
"v5"- Strapi 5.x (usesdocumentId, new relations format)"v4"- Strapi 4.x (uses numericid)
Output Configuration
Code output format.
"typescript"- Generate.tsfiles with TypeScript syntax"jsdoc"- Generate.jsfiles with JSDoc type annotations
Actions are only available in TypeScript mode. JSDoc projects can only generate types, services, schemas, and upload helpers.
Module system for JavaScript output (JSDoc only). Auto-detected from
package.json if not specified."esm"- ES Modules (import/export)"commonjs"- CommonJS (require/module.exports)
outputFormat: "jsdoc".Output directory for generated files, relative to project root.Example:
"src/lib/strapi" or "generated/strapi"Features
Control which files to generate. All features default totrue except upload.
Generate TypeScript type definitions for all content types, components, and API responses.Generates:
- Type interfaces for each content type
- Component types
- Relation types
- API response wrappers
- Locale types
Generate service classes for API calls (CRUD operations, queries, filters).Generates:
- Service with methods like
findMany(),findOne(),create(),update(),delete() - Typed query builders
- Population helpers
- Locale switching
Generate framework-specific server actions (currently Astro only).Generates:
- Type-safe server actions
- Automatic validation
- Error handling
Generate Zod validation schemas for form libraries (React Hook Form, TanStack Form, etc.).Default:
true for TypeScript, false for JSDocGenerates:- Zod schemas for create/update operations
- Field validation based on Strapi schema constraints
- Enum validation
- Required/optional field handling
Generate file upload helpers for browser and server.Generates:
- Public upload client for browser
- Server action for secure uploads (framework-specific)
- Type-safe upload methods
PUBLIC_STRAPI_URLPUBLIC_STRAPI_UPLOAD_TOKEN
Schema Options
Customize validation schema generation.Use advanced relation format with Advanced format supports:
connect/disconnect/set operations instead of simple ID arrays.- Simple (default)
- Advanced
connect- Add relations while preserving existingdisconnect- Remove specific relationsset- Replace all relationslocale- Target specific locale for i18n contentstatus- Target draft/published versionsposition- Control ordering (before, after, start, end)
Advanced Options
Include draft content types in generation. Only applies to content types with
draftAndPublish enabled.When true, generated types will include draft-specific fields and methods.Generate strict types with no optional fields. All fields marked as non-required in Strapi will still be required in TypeScript.
Complete Example
Type Definitions
Config File Location
The CLI searches for config files in this order:strapi.config.tsstrapi.config.jsstrapi.config.mjsstrapi.config.cjs
package.json).
Environment Variables
The config loader automatically resolves environment variables from.env files using dotenv. Variables are loaded before config parsing.
Supported patterns:
process.env.VARIABLE_NAME- Direct environment variable access
- Fallback chains:
process.env.VAR1 || process.env.VAR2 || "default"
tokenfield: Automatically triesSTRAPI_SYNC_TOKEN→STRAPI_TOKENif not explicitly set
Validation
Configuration is validated using Zod with theconfigSchema. Invalid configurations will throw detailed error messages.