Strapi with Astro

Connecting an Astro site to Strapi content through the REST API, with a typed fetch wrapper, a deliberate choice between static and server rendering, and rebuilds when editors publish.

On this page

How Strapi with Astro works and where the work sits

An Astro front end that needs editorial content from a self-hosted Strapi instance does not need a dedicated connector. Astro's Strapi guide keeps the Strapi address in a STRAPI_URL environment variable and wraps calls to the Strapi /api endpoints in a small fetch function, so the integration is plain HTTP between two systems you run. That simplicity moves the real work elsewhere. Most of the effort sits in three places: the data contract between content types and page components, the build behavior that decides when Astro fetches content, and the rebuild trigger that tells the site something changed. Your team should decide early which of those it will own and which a partner will build.

The first decision is the data contract. Strapi 5 changed the API response format compared with v4, and it identifies entries by documentId rather than the numeric id that older examples use. Before writing the wrapper, confirm the response shape and the identifier handling against the exact Strapi version you run, including any populate behavior for components, dynamic zones and media. Your public API permissions and any token used at build time also need to be settled, because a build that works in development can fail once the instance sits behind a reverse proxy or in a separate network. Upgrading Strapi later will touch this layer again, so treat the wrapper and its types as a versioned boundary rather than scattered fetch calls.

The second decision is whether pages are built ahead of time or rendered on request. A static build fetches Strapi content during the build, so every content change needs a new build before readers see it. Server rendering fetches content per request, which shifts load and availability requirements onto the Strapi instance and the hosting path between them. Your team should write down which pages must reflect a change within minutes, which can wait for a scheduled build, and what happens when Strapi is unreachable during a build. The rebuild trigger, meaning the webhook or pipeline step that starts a new build after a publish, is a separate piece of work with its own choices about which events to listen to and how to avoid repeated builds. Ask any partner to show how each of these choices is tested against your own environment.

What you need before connecting Astro to Strapi

Most connection problems trace back to a few prerequisites: the Strapi version, its database and Node.js runtime, the URL the build can reach, and the read permissions the Astro project uses. Confirm each one before writing the fetch wrapper, because a mismatch here usually surfaces as empty pages or failed builds rather than a clear error.

Strapi 5 on a supported stack

Confirm the Strapi instance runs Strapi 5, since Strapi v4 reached end of life on April 30, 2026 and will receive no further updates. Check that the database is PostgreSQL 14 or later, MySQL 8.0 or later, MariaDB 10.3 or later, or SQLite 3, because Strapi 5 does not support MongoDB or other NoSQL databases. Record the exact versions so the Astro team knows which API response format to expect.

Strapi installation requirements

Active or Maintenance LTS Node.js

Strapi 5 runs only on Active or Maintenance LTS Node.js versions, so the Strapi server and the Astro build machines should be checked against the same supported list. Astro has its own Node.js requirement, so the two can differ. Pin a version in both projects and confirm it in CI, since an unsupported runtime on either side can break the build before any content is fetched.

Strapi installation requirements

A Strapi URL reachable from builds

Decide where the Strapi URL is used. Static builds run on CI runners or build servers that must reach the Strapi /api endpoints over the network, while server-rendered Astro runs on the application host. Store the address in the STRAPI_URL environment variable for each environment, and confirm that the build network can route to it, including any private DNS, VPN or firewall rules.

Public or token-based read access

Decide whether anonymous visitors can read the content types Astro needs. Public read permissions suit published marketing content, while a read-only API token suits drafts, preview or private collections. Check that each content type the site uses is allowed for the chosen access level, and avoid granting write permissions to the token used by the site. Test with a request that has no token to confirm exactly what the public can see.

Astro project and Node.js version

Confirm the Astro version and its Node.js requirement in the target project before adding the Strapi guide's code. Decide whether the project builds static output or runs server rendering, because that choice changes where the fetch wrapper runs and which environment variables the runtime must see. Record both versions in the project README so later upgrades start from a known baseline.

Astro Strapi guide

Environment variables in every environment

Astro reads STRAPI_URL at build time for static output and at request time for server rendering, so the variable must exist wherever those steps run. Confirm it is set in local development, preview, staging and production, and that it points to the matching Strapi instance. A missing or stale value often produces an error only in one environment, so verify each one with a test build.

Configuring STRAPI_URL and the first Astro fetch

This sequence connects an Astro project to a Strapi instance through an environment-specific STRAPI_URL, a small typed fetch wrapper, and the permissions that let Astro read published content. It ends with one collection rendering in a development build.

  1. Confirm the Strapi instance and its API base URL

    Before writing any Astro code, the team confirms which Strapi instance the site will read from in each environment: a local instance for development, and a staging and production instance that the team already runs. Someone with access to the Strapi admin panel opens a content type, checks that the instance responds at its /api path, and notes the base URL, including the protocol and port. The check is a successful request to a known collection in a browser or with curl, which returns JSON rather than an error page. Strapi 5 must run on a supported Node.js version and database, so confirm that the instance is a supported version before building against it.

  2. Set STRAPI_URL for each environment

    The developer adds a STRAPI_URL variable to a local .env file for development and sets the same key separately in the staging and production build environments, so each build points at the correct instance. The value is the base URL without a trailing path, such as the host and port of the Strapi server. Astro reads environment variables through its own configuration, so the variable should be kept out of version control and accessed in server-side code. The check is a short script or temporary log line that prints the value in a dev build and shows the expected host, with no secrets printed.

  3. Create a typed fetch wrapper for the /api endpoints

    The developer writes one module, for example in a src/lib folder, that reads STRAPI_URL, builds the request path under /api, and returns typed data. The wrapper should handle a non-OK response by throwing an error that names the endpoint, so a wrong URL or a missing permission is visible during the build. Types for each content type are written by hand or generated from the Strapi schema, and they should match the response format of the Strapi version in use. The check is that the module compiles under the project's TypeScript check without errors and that a unit-level call with a known path returns the expected shape.

  4. Confirm public or token permissions on each content type

    In the Strapi admin panel, an administrator opens the Users & Permissions settings for the Public role and enables the find and findOne actions only for the content types the Astro site needs. If the site must read draft content or private fields, the team creates an API token with read access limited to those content types instead of enabling more public actions. Each content type is checked one at a time so that no collection is exposed by accident. The check is an unauthenticated request, or a token request, against each collection that returns the expected entries, and a request against a content type that was left out returns a forbidden response.

  5. Fetch one collection in a development build

    The developer calls the wrapper from one Astro page or endpoint file, using a single collection such as articles, and runs the development server. The first fetch should request a small, known set of fields so that the response is easy to inspect. The team should also confirm how the Strapi 5 response shape places fields on each entry, since the wrapper types must match it. The check is a logged response in the terminal that lists the expected number of entries, with the titles or slugs visible in the output.

  6. Render the fetched content on a page

    The developer replaces the logged output with a simple Astro page that loops over the entries and renders the title and a link for each one. The page should handle an empty collection and a failed request without breaking the whole build, and the error message should name the endpoint. The developer loads the page in the local dev server and compares it with the entries in the Strapi admin panel. The check is a rendered page whose list matches the published entries in Strapi, with one draft entry confirmed as absent when the public role is used.

  7. Record the configuration for the other environments

    Before moving to static builds or server rendering, the team writes down the variables, the Strapi role or token used, the content types exposed, and the commands that run the fetch in each environment. The notes should name the owner for the Strapi permissions and say who rotates any API token. This record makes the next decisions, such as build mode and content change triggers, easier to review. The check is a short setup note in the project repository that a second developer can follow to reproduce the first fetch on a clean machine.

Designing a typed fetch wrapper for Strapi responses

The wrapper should be typed against the response shape of the Strapi version your project actually runs, so the first decision is confirming that version on staging and production. In Strapi 5, each entry carries a documentId string alongside the numeric id, and your types should use documentId as the key for detail routes and for linking entries together. Collection responses return a data array with a meta object holding pagination details, while single-entry responses return data as one object. Model both shapes explicitly in the wrapper so that a list call and a detail call cannot be mixed up at compile time. Confirm the exact field names against a real response from your instance before you write the types.

Relations, components, dynamic zones and media are not returned unless the request asks for them, so the wrapper should accept a typed populate parameter and serialize it into the query. Declare the return type to match the fields that population produces, so an Astro page that reads a cover image URL fails the build when its query omits the media field. Media fields are themselves entries with their own attributes, which means a shared media type belongs in your common types rather than being redefined per page. Keep populate narrow for each page template. A broad wildcard populate makes responses heavier and makes the types harder to keep accurate over time.

The Strapi-Response-Format: v4 header is a migration aid that asks a Strapi 5 instance to return the older response format while code is moved over. It is not a target for new Astro code. If your team is still migrating from v4, put the v4 envelope behind a single adapter in the wrapper, then remove the header and the adapter once every page reads v5 shapes. Strapi v4 reached end of life on April 30, 2026, so treat that adapter as a temporary step with a planned removal date. Read the Strapi v4 to v5 migration guide before deciding how long the adapter should stay.

Choosing static builds or server rendering for Strapi content

With fully static output, Astro fetches every Strapi entry it needs at build time and writes plain HTML and assets to disk or a CDN. Visitors never call Strapi directly, so the public site does not depend on the CMS being available at request time. The cost is that content changes only appear after a new build, which makes the rebuild trigger part of the editorial workflow.

  • Build time: Build duration grows with the number of pages and entries fetched. Large catalogs or many dynamic routes make each publish slower, so measure a full build against your real content volume.
  • Content freshness: An editor's change is live only after the build completes and deploys. Confirm how long that takes in your pipeline and tell editors what to expect.
  • Strapi API load: Load is concentrated in build runs. Many visitors add no API calls, but frequent rebuilds still send many requests at once.
  • Preview needs: Previews of unpublished drafts need a separate preview build or a draft-aware route, which must be planned alongside the static output.
  • Hosting requirements: Any static host or CDN works, so hosting is simple. Check that your Astro version and output setting match the build target you intend to use.

Confirm build duration and rebuild latency with your own content volume before committing to this model.

How content moves from Strapi into the Astro build

The path starts when an editor publishes an entry in the Strapi admin panel. A Strapi webhook then calls a build hook, which starts an Astro build. During the build, Astro calls the Strapi /api endpoints at the address held in STRAPI_URL, and the output reaches the browser either as static files or as server responses. A cache or CDN purge closes the loop, so readers see the change. The trust boundary sits between the public site and the Strapi admin network: only the build process and the Strapi API should cross it, and the admin panel should not be reachable from the public internet.

Publishing in Strapi triggers an Astro build that reaches readers through the CDN.

Rebuilding the Astro site when Strapi content changes

The core decision in this section is how often a Strapi save should trigger an Astro build. Strapi can send webhooks for entry events such as create, update, publish and unpublish, and each webhook can be limited to the content types that actually change the public site. A typical flow is that an editor publishes an entry, Strapi posts a webhook to a receiver, and the receiver calls the build hook of your static host (for example, a deploy hook from Netlify, Vercel or a self-managed CI runner). Each step has a control you own: the event list and model filter in Strapi, the receiver's logic, and the build hook URL and its secrecy. Map every content type in your Astro site to the event that matters for it before you wire anything up, and leave out types that only feed internal dashboards.

Rebuild storms happen when every save, including draft autosaves, bulk imports and several editors working on one page, starts a full site build. Builds queue up, later builds overwrite earlier ones, and the site spends most of its time rebuilding rather than serving the latest content. Reduce this by filtering on event and content type, debouncing or batching requests in the receiver, and skipping builds when nothing visible has changed. Test with a realistic editorial day: a bulk import, a scheduled release and two editors on the same entry. Confirm how your host queues concurrent build hook calls and whether it cancels or stacks them. The Strapi event and model filter choices, and the security of the build hook URL, are covered in more depth in rebuilding static sites on Strapi content changes, which you should read before choosing events.

Build frequency, build time and cost depend on your hosting plan and build minute allowances, which vary by provider and plan. Confirm with your host how many builds a month your plan includes, what a full Astro build costs in build minutes for your site size, and whether incremental or on-demand rendering reduces that load. Also confirm the Strapi side: the webhook settings available in your Strapi edition and plan, and any hosting limits that apply if you run Strapi Cloud rather than self-hosting. Write these answers into your rebuild design before choosing a publish cadence, because a cadence that is cheap for a small blog can be expensive for a large catalog.

Mapping Strapi fields and roles to Astro pages and build data

This table maps each published Strapi content type to the Astro route, fetch pattern and Strapi permission it needs. Read each row as a decision to confirm with your editors before the build starts, since the route and permission choices determine what the build can see. The main takeaway is that single types, collections, relations and locale fields should each be mapped explicitly, so the public role grants only what the pages render.

Content typeAstro route and fetch patternStrapi access and build notes
Site settings (single type)Layout file loaded once per build, such as a header and footer shared across pagesPublic read on the single type only; keep editor-only fields out of the public response by not requesting them
Page or article (collection)Dynamic route, such as src/pages/articles/[slug].astro, with getStaticPaths returning one path per entryPublic read with a filter on published entries; confirm that draft content is excluded from the static build
Author or category (relation)Populated into the article props, so the route receives a nested object rather than an IDPopulate only the relations the template renders; each populated relation needs its own read permission for the role
Content blocks (components or dynamic zones)A component map in Astro that renders each block type, with unknown types skippedComponents inherit the parent read permission in the public role; confirm this in your Strapi version before relying on it
Media fields (uploads)Image URLs built from STRAPI_URL plus the stored file path, passed to an image componentUploads are served by Strapi unless a provider is configured; verify that the public role can read the upload files
Localized content (locale field)One route per locale, such as /fr/articles/[slug], driven by the locale value on each entryRequest each locale explicitly in the fetch; confirm which locales your editors publish and which are public
Preview or draft contentUsually a separate server-rendered route, not part of the static buildRequires an authenticated token with draft access; keep that token out of the static output and the client bundle

Securing the Astro to Strapi connection

An Astro site that reads Strapi is a client of your CMS, and every credential, origin and URL it uses can leak into a public page or a build log. The cards below cover the controls that connect the two systems safely, from the environment variable to the rebuild trigger. The settings themselves sit in the Strapi security configuration topic, so treat these cards as the checks that tie Astro's build to those settings.

Keep STRAPI_URL server-side

Astro's Strapi guide reads the Strapi URL from a STRAPI_URL environment variable, and that value is only needed where data is fetched. Read it in frontmatter or server code, not in client-side scripts or islands, so the URL is not copied into browser bundles. Check the built dist output with a search for the variable's value before each release. Confirm which variables your Astro version exposes to the client, because the prefix rules determine what ships.

Astro Strapi guide

Limit public permissions to published content

Anonymous read access in Strapi should cover only the content types and fields the site renders, and only published entries. Draft content, internal collections and admin-only fields should stay closed to the public role. Review each content type's find and findOne permissions against the page list, and confirm that unpublished editorial work cannot reach a static build through the public API.

Strapi access docs

Use a read-only API token for builds

When the build needs access that public permissions do not cover, create a Strapi API token with read-only scope and use it only in the build environment. Store it in the CI secret store, never in the repository or a .env file committed to git. Rotate it on a schedule and on staff changes, and confirm that a leaked token can read only what the site already publishes.

Restrict CORS to Astro origins

Server-rendered Astro pages call Strapi from the server, so browser CORS rules matter only when client code calls the API directly. Allow the production and preview origins of the Astro site in Strapi's CORS settings and remove wildcards. Test from an unlisted origin to confirm that the browser is refused, and record the allowed list in the deployment runbook so it changes with the domain.

Protect the build hook secret

A rebuild trigger from Strapi webhooks to your static host or CI pipeline is a credential that can start builds. Use a long random secret in the webhook URL or header, store it in the CMS and host secret managers, and reject requests that lack it. Rotate it if an editor leaves or a log exposes it, and confirm that the endpoint ignores events from content types the site does not render.

Review upload and media URL exposure

Strapi uploads are served from URLs that anyone with the link can open, and Astro pages typically embed those URLs directly. Confirm which upload folders are public, whether private media needs signed URLs, and whether the media provider or local public/uploads path exposes files that were meant to stay in review. Check that image URLs in the built HTML point only at assets the site is allowed to publish.

Common Astro and Strapi integration failures and fixes

This table lists the failures teams most often hit when Astro reads Strapi content, with the likely cause and the fix for each. Read it as a checklist during build setup and again when a build or page breaks after launch.

FailureLikely causeFix
Build fails or fetches nothing in CISTRAPI_URL is set locally in .env but missing or pointing at localhost in the CI or hosting environmentSet STRAPI_URL as a build secret in every environment, and fail the build with a clear message when it is empty
403 Forbidden on API callsThe Public or Authenticated role in Strapi does not grant find or findOne on the content typeGrant read permissions on the required content types for the role the frontend uses, then test each endpoint with curl before the build
Empty data after upgrading to Strapi 5Strapi 5 changed the API response shape, so code reading the v4 nested attributes object gets undefined valuesUpdate the fetch wrapper and page code to read flat fields and documentId, or confirm the Strapi-Response-Format v4 header is used during migration
Pages stay stale after publishingStatic output was built once and no rebuild runs when entries are published or updatedTrigger a rebuild from a Strapi webhook on publish and unpublish events for the relevant content types, as covered in the sibling topic on static rebuilds
Images and files break with relative URLsMedia fields return paths such as /uploads/file.jpg that resolve against the Astro domain, not the Strapi hostPrefix media URLs with STRAPI_URL in the fetch wrapper, or serve media through the upload provider's absolute URLs
CORS errors in server-rendered pagesAstro runs the fetch on the server, so CORS should not apply, but browser-side calls to Strapi from client code are blocked by the allowed origins listKeep data fetching in server code, or add the Astro origin to Strapi's CORS settings and review them against the security configuration guidance
Build times out or runs very longOne request per entry or per relation runs in sequence, multiplying latency across many pagesFetch collections in one paginated call with populate for needed relations, and run independent requests in parallel with a concurrency limit
Server-rendered pages return errors when Strapi is downNo timeout, retry or fallback in the fetch wrapper, so one failed request fails the whole pageSet a request timeout, handle non-2xx responses explicitly, and decide whether a page shows cached content or an error

Questions teams ask before connecting Astro to Strapi

What drives the cost of connecting Astro to Strapi?

The main cost drivers are the size and shape of the content model, the rendering mode you choose, how much rebuild automation you need, and how many environments must stay in step. A site with a few collections and simple pages costs far less to connect than one with nested components, dynamic zones, localized content and separate staging and production Strapi instances. Ask any partner to break the quote into discovery, content model review, the fetch layer, page templates, rebuild triggers, hosting setup and handover, so you can see which parts scale with your scope. Hosting and Strapi plan fees recur on their own schedule and are separate from the one-time build.

How long does a first Astro and Strapi integration take?

Duration depends on scope rather than on the framework pair. A small integration with one content type set, a typed fetch wrapper and a static build can be a short, contained piece of work, while a multi-language site with previews, server rendering and automated rebuilds takes longer. Your content model and the number of page templates set most of the effort. Ask for a timeline tied to the written scope, with named dependencies such as content sign-off, API token creation and hosting access, because those often decide when the work can close.

What does our team need to supply before the build starts?

Before work starts, you need to supply four things. First, a content model that names the collections, single types, components and relations editors will use. Second, a permissions plan that states which roles can read published content and which tokens the site may hold. Third, a hosting decision covering where Strapi and the Astro site run, and where the database and media files live. Fourth, a build pipeline that can run astro build with a STRAPI_URL value for each environment and receive a signal when content changes. Missing any of these usually adds rework later in the project.

Can an in-house developer connect Astro to Strapi alone?

A developer who knows both Astro and Strapi can build a basic connection without outside help. The Astro guide covers storing the Strapi URL in an environment variable and wrapping calls to the Strapi /api endpoints, which is the core of the work. The harder parts are usually outside that guide: designing the content model so it stays stable, deciding between static builds and server rendering, securing read tokens, and keeping builds reliable when editors publish often. If your team lacks one of these skills or lacks time for the handover, a fixed-scope engagement can cover the gap and leave the code and runbook with you.

Should we choose static builds or server rendering for Astro on Strapi?

Choose static builds when content changes on a predictable schedule and pages can tolerate a rebuild after each publish. Choose server rendering when pages must reflect edits almost immediately, depend on per-user data, or need previews for editors. Static output keeps hosting simple and reduces load on Strapi, but every relevant change triggers a build, so build time and the number of affected pages become operating costs. Server rendering removes most rebuild work and adds a running Node process, caching decisions and more load on the Strapi API. Test both against your publishing rate before you commit.

Which Strapi plan features matter for an Astro site?

For most Astro sites, the API and content features matter more than the admin add-ons. The self-hosted Community Edition, and the Growth and Enterprise plans, all include REST and GraphQL APIs and unlimited entries and API calls, so the content delivery side does not depend on the plan. Features that do depend on the plan include SSO for administrator login, content history and releases (from Growth), and audit logs and review workflows (Enterprise). Check the current feature list on the Strapi self-hosted pricing page before you choose, since Strapi revises plans over time.

What breaks when Strapi content changes and the site does not rebuild?

Editors publish changes that never appear on the live site, or they appear only after someone runs a manual build. This happens when the rebuild trigger is missing, points to the wrong environment, or fails silently because its token expired. Confirm that each publish, unpublish and delete event reaches the build pipeline, that failed builds alert someone, and that a manual rebuild path exists. Test the full loop in staging by publishing an entry and checking the production URL before go-live.

Which Strapi version should a new Astro project target?

New projects should target Strapi 5, because Strapi v4 reached end of life on April 30, 2026, and its final release will receive no further updates. Strapi 5 supports PostgreSQL 14 or later, MySQL 8.0 or later, MariaDB 10.3 or later and SQLite 3, and it does not support MongoDB. It also runs only on Active or Maintenance LTS Node.js versions, so confirm your Node version against the Strapi installation requirements before you set up the build server. Any existing v4 site should be planned for upgrade before it is connected.

How DeployOpen works on this

DeployOpen scopes the Astro and Strapi work in writing before build starts, then builds, tests, documents and hands over the integration in infrastructure you control. Engagements are fixed-scope, and ongoing support is available as a retainer.

How we scope

  • Confirm which Astro output mode fits each page: static, server rendering or a mix of both
  • Map the Strapi content types, relations and media fields each Astro page needs
  • Agree where STRAPI_URL is set per environment and which Strapi URL the build reads
  • Record the rebuild trigger, expected content change frequency and who approves publishing

How we build

  • Set up the STRAPI_URL configuration and keep the Strapi token out of client-side code
  • Write a typed fetch wrapper that handles errors, pagination and the response shape in use
  • Build the Astro pages on the agreed output mode, with preview and draft handling where needed
  • Test builds against staging Strapi content before production publishing is connected

How we hand over

  • Deliver the Astro project, configuration notes and the typed data layer in your repository
  • Document the environment variables, build commands and the content model dependencies
  • Walk your team through a rebuild from a Strapi content change and the rollback steps
  • Provide a written runbook covering failed builds, stale content and token rotation

How we support

  • Offer retainer support for Astro and Strapi version updates and dependency changes
  • Review the integration when the Strapi content model or Astro output mode changes
  • Retest rebuild and access behavior after Strapi upgrades in your environment
  • Confirm support scope, response expectations and fees in the written agreement

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.