Deployment · By Rivtor · Updated
Deploy an Astro static frontend with a Node.js API
Build a static Astro site separately from a Node.js API, supply only public API configuration to browser code and keep database credentials in the API service. If the Astro project uses server rendering, select an appropriate server adapter rather than treating it as static output.
See the Rivtor deployment workflow →
Confirm the Astro rendering mode
Inspect the project configuration before choosing a service type. A static output directory can be hosted without a long-running Astro process. Routes that require server rendering or server-side sessions need an adapter and runtime that support them. Static assets and a Node server are different production artifacts.
For an illustrative repository, web contains the Astro project and api contains an Express application with a production start command. Build web to its configured output directory. Run api on the assigned port and interface. The database belongs behind the API.
Know when the API is called
| Call location | Configuration consequence |
|---|---|
| Astro build step | API/data must be available when generating pages |
| Browser script | URL is public and must be browser-reachable |
| Server-rendered route | Needs a supported server runtime and private secrets |
A build-time fetch becomes a snapshot in static output. It will not update itself when a database record changes. Use a deliberate rebuild or browser request for fresh data, depending on the page’s requirements.
Keep the public configuration public
Astro’s PUBLIC_ convention identifies values intended for client-side use. Treat a public API origin as non-secret; never put a database connection string or privileged service token there. Configure CORS on the API for the deployed frontend when browser calls cross origins.
On Rivtor, framework detection documents Astro static builds and Node services. Confirm the output directory and detected service roots. Do not assume every adapter or server-rendering mode follows the static deployment path.
Check static pages and live operations
Visit the home page and a nested route directly. Confirm assets load and browser API requests reach the deployed hostname. If a page was generated at build time, compare its content with the source snapshot so stale data is not mistaken for a routing bug.
Exercise a synthetic database operation through the API and confirm it survives an API restart. If the project requires server-only Astro features, stop and choose the correct adapter and runtime before publishing a guide claiming the static configuration is sufficient.