Quick setup for your Astro + Contentful starter template, optimized for Cloudflare Pages.
-
Install dependencies
npm install
-
Set up environment variables
cp .env.example .env # Edit .env with your Contentful API keys -
Start development
npm run dev
Visit http://localhost:4321 to see your site!
The template works without Contentful, but to use the full content management features:
- Go to contentful.com
- Create a new space
- Note your Space ID
Create these content types in your space:
Blog Post (blogPost)
- Title (Short text)
- Slug (Short text)
- Excerpt (Long text)
- Content (Rich text)
- Featured Image (Media)
- Author (Short text)
- Publish Date (Date)
- Tags (Short text, multiple)
Page (page)
- Title (Short text)
- Slug (Short text)
- Content (Rich text)
- Go to Settings > API keys
- Copy Space ID and Content Delivery API access token
- Add to your
.envfile
CONTENTFUL_SPACE_ID=your_space_id
CONTENTFUL_DELIVERY_TOKEN=your_delivery_token
CONTENTFUL_ENVIRONMENT=masterThis template is specifically designed for Cloudflare Pages:
- No Node.js SDK - Uses native
fetch()API instead of Contentful's Node SDK - Build-time Fetching - All content is fetched during the build process
- Static Output - Generates static HTML files for optimal performance
- CDN Images - Images are served directly from Contentful's CDN
- Connect your repository to Cloudflare Pages
- Set build settings:
- Build command:
npm run build - Build output directory:
dist
- Build command:
- Add environment variables in Cloudflare Pages dashboard:
CONTENTFUL_SPACE_IDCONTENTFUL_DELIVERY_TOKENCONTENTFUL_ENVIRONMENT
✅ Working Features
- Development server
- Production build
- Basic site structure
- Responsive design
- TypeScript support
- SEO components
- Static page generation
- Blog functionality
- Dynamic content loading
- Content management
- Add content to your Contentful space
- Customize the design and layout
- Deploy to Cloudflare Pages
"Cannot find module 'contentful'"
- Run
npm installto install dependencies
"Contentful client error"
- Check your environment variables in
.env - Verify your Contentful API keys
"TypeScript errors"
- Run
npm run type-checkto see specific issues - Ensure all imports are correct
This template uses a Cloudflare-first approach:
- No Node.js dependencies - Everything works in Cloudflare's edge environment
- Build-time content fetching - Content is fetched once during build, not on every request
- Static site generation - Perfect for Cloudflare Pages' static hosting
- Native web APIs - Uses
fetch()instead of external SDKs - Optimal performance - No runtime API calls, just static HTML with CDN images