अपने प्रश्न को पूछें और दस्तावेज़ का सारांश प्राप्त करें, इस पृष्ठ और आपके चुने हुए AI प्रदाता का उपयोग करके
इस पृष्ठ की सामग्री एक AI द्वारा अनुवादित की गई है।
अंग्रेजी में मूल सामग्री के अंतिम संस्करण देखेंअगर आपके पास इस दस्तावेज़ को सुधारने के लिए कोई विचार है, तो कृपया GitHub पर एक पुल अनुरोध सबमिट करके योगदान देने में संकोच न करें।
दस्तावेज़ के लिए GitHub लिंकदस्तावेज़ का Markdown को क्लिपबोर्ड पर कॉपी करें
import ReadMore from '/components/ReadMore.astro';
import { Steps } from '@astrojs/starlight/components';
import StaticSsrTabs from '/components/tabs/StaticSsrTabs.astro';
You can deploy full-stack applications, including front-end static assets and back-end APIs, as well as on-demand rendered sites, to both Cloudflare Workers and Cloudflare Pages.
This guide includes:
:::note
Cloudflare recommends using Cloudflare Workers for new projects. For existing Pages projects, refer to Cloudflare's migration guide and compatibility matrix.
:::
Read more about using the Cloudflare runtime in your Astro project.
Prerequisites
To get started, you will need:
- A Cloudflare account. If you don’t already have one, you can create a free Cloudflare account during the process.
Cloudflare Workers
How to deploy with Wrangler
```bash npm install wrangler@latest --save-dev ```2. If your site uses on demand rendering, install the @astrojs/cloudflare adapter.
This will install the adapter and make the appropriate changes to your `astro.config.mjs` file in one step. ```bash npx astro add cloudflare ``` Then, create a `.assetsignore` file in your `public/` folder, and add the following lines to it: ```txt title="public/.assetsignore" _worker.js _routes.json ``` <ReadMore>Read more about [on-demand rendering in Astro](/en/guides/on-demand-rendering/).</ReadMore>3. Create a Wrangler configuration file.
<StaticSsrTabs> <Fragment slot="static"> ```jsonc // wrangler.jsonc { "$schema": "node_modules/wrangler/config-schema.json", "name": "my-astro-app", // Update to today's date "compatibility_date": "2025-03-25", "assets": { "directory": "./dist", "not_found_handling": "404-page" // If you have a custom `src/pages/404.astro` page } } ``` </Fragment> <Fragment slot="ssr"> ```jsonc // wrangler.jsonc { "$schema": "node_modules/wrangler/config-schema.json", "name": "my-astro-app", "main": "./dist/_worker.js/index.js", // Update to today's date "compatibility_date": "2025-03-25", "compatibility_flags": ["nodejs_compat"], "assets": { "binding": "ASSETS", "directory": "./dist" }, "observability": { "enabled": true } } ``` </Fragment> </StaticSsrTabs>4. Preview your project locally with Wrangler.
```bash npx astro build && npx wrangler dev ```5. Deploy using npx wrangler deploy.
```bash npx astro build && npx wrangler deploy ```After your assets are uploaded, Wrangler will give you a preview URL to inspect your site.
Read more about using Cloudflare runtime APIs such as bindings.
How to deploy with CI/CD
You can also use a CI/CD system such as Workers Builds (BETA) to automatically build and deploy your site on push.
If you're using Workers Builds:
-
Log in to the Cloudflare dashboard and navigate to Workers & Pages. Select Create.
-
Under Import a repository, select a Git account and then the repository containing your Astro project.
-
Configure your project with:
- Build command: npx astro build
- Deploy command: npx wrangler deploy
-
Click Save and Deploy. You can now preview your Worker at its provided workers.dev subdomain.
Cloudflare Pages
How to deploy with Wrangler
```bash npm install wrangler@latest --save-dev ```2. If your site uses on demand rendering, install the @astrojs/cloudflare adapter.
This will install the adapter and make the appropriate changes to your `astro.config.mjs` file in one step. ```bash npx astro add cloudflare ``` <ReadMore>Read more about [on demand rendering in Astro](/en/guides/on-demand-rendering/).</ReadMore>3. Preview your project locally with Wrangler.
```bash npx astro build && npx wrangler pages dev ./dist ```4. Deploy using npx wrangler deploy.
```bash npx astro build && npx wrangler pages deploy ./dist ```After your assets are uploaded, Wrangler will give you a preview URL to inspect your site.
How to deploy a site with Git
-
Log in to the Cloudflare dashboard and navigate to Compute (Workers) > Workers & Pages. Select Create and then select the Pages tab. Connect your git repository.
-
Configure your project with:
- Framework preset: Astro
- Build command: npm run build
- Build output directory: dist
-
Click the Save and Deploy button.
Troubleshooting
Client-side hydration
Client-side hydration may fail as a result of Cloudflare's Auto Minify setting. If you see Hydration completed but contains mismatches in the console, make sure to disable Auto Minify under Cloudflare settings.
Node.js runtime APIs
If you are building a project that is using on-demand rendering with the Cloudflare adapter and the server fails to build with an error message such as [Error] Could not resolve "XXXX. The package "XXXX" wasn't found on the file system but is built into node.:
-
This means that a package or import you are using in the server-side environment is not compatible with the Cloudflare runtime APIs.
-
If you are directly importing a Node.js runtime API, please refer to the Astro documentation on Cloudflare's Node.js compatibility for further steps on how to resolve this.
-
If you are importing a package that imports a Node.js runtime API, check with the author of the package to see if they support the node:* import syntax. If they do not, you may need to find an alternative package.