2.5 KiB
2.5 KiB
Strapi Integration Guide
Setup
- Start Strapi CMS:
cd cms/cms
npm run develop
- Configure environment variables:
- In
backend/.env, add your Strapi API token (create one in Strapi admin panel)
Content Types
Create these content types in Strapi admin panel:
Article
- Fields:
title(Text, required)description(Text)content(Rich Text, required)slug(UID, target field: title)publishedAt(DateTime)author(Relation with Author)category(Relation with Category)tags(Relation with Tag)
- Settings: Draft & publish enabled
Author
- Fields:
name(Text, required)bio(Text)avatar(Media)
Category
- Fields:
name(Text, required)description(Text)parent(Relation with Category, self-referential)
Tag
- Fields:
name(Text, required)
Webhook Configuration
In Strapi admin panel, go to Settings → Webhooks and create a webhook:
Article Sync Webhook
- Name: Backend Article Sync
- URL:
http://localhost:3000/api/v1/webhooks/strapi/article - Events:
- ✓ entry.create
- ✓ entry.update
- ✓ entry.delete
- Headers: None required for now
- Send headers: No
API Token Creation
- Go to Settings → API Tokens → Create new API Token
- Name: Backend Integration
- Duration: Unlimited
- Token Type: Full access (or customize as needed)
- Copy the generated token to
backend/.envasSTRAPI_API_TOKEN
Manual Sync
Trigger a full sync manually:
curl -X POST http://localhost:3000/api/v1/webhooks/strapi/sync/all
Data Flow
- Content is created/updated in Strapi
- Strapi sends webhook to backend
- Backend fetches the updated content from Strapi API
- Backend syncs content to local SQLite database
- Frontend queries backend API for public content
Testing the Integration
- Create an article in Strapi
- Publish it
- Check if it appears in backend:
curl http://localhost:3000/api/v1/articles - Frontend should now display the article
Troubleshooting
Webhook not triggering
- Check Strapi webhook logs in admin panel
- Verify backend is running on the correct URL
- Check network connectivity
Sync not working
- Verify STRAPI_API_TOKEN is correct
- Check Strapi content type permissions
- Review backend logs for errors
- Test Strapi API directly:
curl http://localhost:1337/api/articles
CORS errors
- Ensure backend CORS includes Strapi URL
- Update
backend/src/main.tsCORS configuration