// @ts-checkimport { defineConfig } from "strapi2front";export default defineConfig({ // Strapi connection url: process.env.STRAPI_URL || "http://localhost:1337", token: process.env.STRAPI_SYNC_TOKEN || process.env.STRAPI_TOKEN, // API prefix (default: "/api") apiPrefix: "/api", // Output format: "typescript" (.ts) or "jsdoc" (.js with JSDoc) outputFormat: "jsdoc", // Module type: "esm" or "commonjs" (auto-detected if not specified) moduleType: "esm", // Output configuration output: { path: "src/strapi", }, // Features to generate features: { types: true, // JSDoc type definitions services: true, // Service functions with JSDoc actions: false, // Actions require TypeScript schemas: true, // Zod validation schemas upload: false, // File upload helpers }, // Strapi version strapiVersion: "v5",});
strapi.config.js
Copy
Ask AI
// @ts-checkconst { defineConfig } = require("strapi2front");module.exports = defineConfig({ // Strapi connection url: process.env.STRAPI_URL || "http://localhost:1337", token: process.env.STRAPI_SYNC_TOKEN || process.env.STRAPI_TOKEN, // API prefix (default: "/api") apiPrefix: "/api", // Output format: "typescript" (.ts) or "jsdoc" (.js with JSDoc) outputFormat: "jsdoc", // Output configuration output: { path: "src/strapi", }, // Features to generate features: { types: true, // JSDoc type definitions services: true, // Service functions with JSDoc actions: false, // Actions require TypeScript schemas: true, // Zod validation schemas upload: false, // File upload helpers }, // Strapi version strapiVersion: "v5",});
3
Set up environment variables
Create or update your .env file:
.env
Copy
Ask AI
# Strapi URLSTRAPI_URL=http://localhost:1337# Sync token: Used by strapi2front to sync schema (development only)# Permissions: content-type-builder (getContentTypes, getComponents), i18n (listLocales)# IMPORTANT: Do NOT deploy this token to productionSTRAPI_SYNC_TOKEN=# Frontend token: Used by your app to fetch content (production)# Configure with only the permissions your app needsSTRAPI_TOKEN=
Create .env.example for your repository:
.env.example
Copy
Ask AI
# Strapi URLSTRAPI_URL=http://localhost:1337# Sync token: Used by strapi2front to sync schema (development only)# Permissions: content-type-builder (getContentTypes, getComponents), i18n (listLocales)# IMPORTANT: Do NOT deploy this token to productionSTRAPI_SYNC_TOKEN=# Frontend token: Used by your app to fetch content (production)# Configure with only the permissions your app needsSTRAPI_TOKEN=
Add .env to your .gitignore to avoid committing sensitive tokens:
If you enable the upload feature, you’ll need an additional token for file uploads:
1
Create Upload Token
In Strapi admin: Settings > API Tokens > Create new API Token
Token name: upload-token
Token type: Custom
Duration: As needed
Permissions:
✅ Upload
upload (only)
❌ No delete or update permissions (security best practice)
2
Add to Environment
Add both the URL and token:
.env
Copy
Ask AI
# Public URL for browser-side uploadsPUBLIC_STRAPI_URL=http://localhost:1337# Upload token: Create in Strapi Admin > Settings > API Tokens# Set permissions: Upload > upload (only, no delete/update)PUBLIC_STRAPI_UPLOAD_TOKEN=your-upload-token-here
The PUBLIC_ prefix makes these variables available in client-side code (framework-specific naming may vary).