Ir al contenido

Config File

Esta página aún no está disponible en tu idioma.

The strapi.config.ts file is the central configuration for strapi2front. It controls how types, services, and schemas are generated.

import { defineConfig } from "strapi2front";
export default defineConfig({
// Strapi server URL
url: process.env.STRAPI_URL || "http://localhost:1337",
// API token for authentication
token: process.env.STRAPI_TOKEN,
// Output configuration
output: {
path: "src/strapi",
},
// Features to generate
features: {
types: true,
services: true,
schemas: true,
},
});

The base URL of your Strapi server.

url: "http://localhost:1337"

Your Strapi API token. Required for fetching the schema.

token: process.env.STRAPI_TOKEN

The API prefix used by Strapi. Defaults to /api.

apiPrefix: "/api" // default

Explicitly set the Strapi version. Auto-detected if not specified.

strapiVersion: "v5" // or "v4"

Choose between TypeScript or JavaScript with JSDoc.

outputFormat: "typescript" // default, generates .ts files
// or
outputFormat: "jsdoc" // generates .js files with JSDoc comments

Configure where files are generated.

output: {
// Base output directory
path: "src/strapi",
}

Enable or disable specific generators.

features: {
types: true, // TypeScript interfaces
services: true, // API service functions
actions: true, // Astro actions (TypeScript only)
schemas: true, // Zod validation schemas
}

Configure Zod schema generation.

schemaOptions: {
// Enable advanced relation format with connect/disconnect/set
advancedRelations: true,
}
import { defineConfig } from "strapi2front";
export default defineConfig({
url: process.env.STRAPI_URL || "http://localhost:1337",
token: process.env.STRAPI_TOKEN,
apiPrefix: "/api",
strapiVersion: "v5",
outputFormat: "typescript",
output: {
path: "src/strapi",
structure: "by-feature",
},
features: {
types: true,
services: true,
actions: true,
schemas: true,
},
schemaOptions: {
advancedRelations: true,
},
});

strapi2front uses two separate tokens for different purposes:

.env
STRAPI_URL=http://localhost:1337
# Sync token: Used by strapi2front to sync schema (development only)
# Permissions: content-type-builder (getContentTypes, getComponents), i18n (listLocales)
STRAPI_SYNC_TOKEN=your-sync-api-token-here
# Frontend token: Used by your app to fetch content (production)
# Configure with only the permissions your app needs
STRAPI_TOKEN=your-frontend-api-token-here