Skip to content

Commit e118214

Browse files
drops official cloudflare pages support (#15480)
1 parent 6c93201 commit e118214

50 files changed

Lines changed: 59 additions & 907 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/young-pandas-talk.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astrojs/cloudflare': major
3+
---
4+
5+
Drops official support for Cloudflare Pages in favor of Cloudflare Workers
6+
7+
The Astro Cloudflare adapter now only supports deployment to Cloudflare Workers by default in order to comply with Cloudflare's recommendations for new projects. If you are currently deploying to Cloudflare Pages, consider [migrating to Workers by following the Cloudflare guide](https://developers.cloudflare.com/workers/static-assets/migration-guides/migrate-from-pages/) for an optimal experience and full feature support.

packages/integrations/cloudflare/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@astrojs/cloudflare",
3-
"description": "Deploy your site to Cloudflare Workers/Pages",
3+
"description": "Deploy your site to Cloudflare Workers",
44
"version": "13.0.0-beta.7",
55
"type": "module",
66
"types": "./dist/index.d.ts",

packages/integrations/cloudflare/src/entrypoints/image-transform-endpoint.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { APIRoute } from 'astro';
22
import { transform } from '../utils/image-binding-transform.js';
3+
// NOTE we have to use `cloudflare:workers` since "live" bindings are not populated to process.env
34
import { env } from 'cloudflare:workers';
45

56
export const prerender = false;

packages/integrations/cloudflare/src/index.ts

Lines changed: 3 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { createRedirectsFromAstroRoutes, printAsRedirects } from '@astrojs/under
66
import { cloudflare as cfVitePlugin, type PluginConfig } from '@cloudflare/vite-plugin';
77
import type { AstroConfig, AstroIntegration, IntegrationResolvedRoute } from 'astro';
88
import { astroFrontmatterScanPlugin } from './esbuild-plugin-astro-frontmatter.js';
9-
import { createRoutesFile, getParts } from './utils/generate-routes-json.js';
9+
import { getParts } from './utils/generate-routes-json.js';
1010
import { type ImageService, setImageConfig } from './utils/image-config.js';
1111
import { createConfigPlugin } from './vite-plugin-config.js';
1212
import {
@@ -24,31 +24,6 @@ export type Options = {
2424
/** Options for handling images. */
2525
imageService?: ImageService;
2626

27-
/** Configuration for `_routes.json` generation. A _routes.json file controls when your Function is invoked. This file will include three different properties:
28-
*
29-
* - version: Defines the version of the schema. Currently there is only one version of the schema (version 1), however, we may add more in the future and aim to be backwards compatible.
30-
* - include: Defines routes that will be invoked by Functions. Accepts wildcard behavior.
31-
* - exclude: Defines routes that will not be invoked by Functions. Accepts wildcard behavior. `exclude` always take priority over `include`.
32-
*
33-
* Wildcards match any number of path segments (slashes). For example, `/users/*` will match everything after the `/users/` path.
34-
*
35-
*/
36-
routes?: {
37-
/** Extend `_routes.json` */
38-
extend: {
39-
/** Paths which should be routed to the SSR function */
40-
include?: {
41-
/** Generally this is in pathname format, but does support wildcards, e.g. `/users`, `/products/*` */
42-
pattern: string;
43-
}[];
44-
/** Paths which should be routed as static assets */
45-
exclude?: {
46-
/** Generally this is in pathname format, but does support wildcards, e.g. `/static`, `/assets/*`, `/images/avatar.jpg` */
47-
pattern: string;
48-
}[];
49-
};
50-
};
51-
5227
/**
5328
* By default, Astro will be configured to use Cloudflare KV to store session data. The KV namespace
5429
* will be automatically provisioned when you deploy.
@@ -128,8 +103,6 @@ export default function createIntegration(args?: Options): AstroIntegration {
128103

129104
updateConfig({
130105
build: {
131-
client: new URL(`./client/`, config.outDir),
132-
server: new URL('./_worker.js/', config.outDir),
133106
redirects: false,
134107
},
135108
session,
@@ -265,6 +238,7 @@ export default function createIntegration(args?: Options): AstroIntegration {
265238
},
266239
});
267240

241+
// QUESTION could be removed based on https://developers.cloudflare.com/workers/configuration/compatibility-flags/#enable-auto-populating-processenv
268242
// Assign .dev.vars to process.env so astro:env can find these vars
269243
const devVarsPath = new URL('.dev.vars', config.root);
270244
if (existsSync(devVarsPath)) {
@@ -317,7 +291,7 @@ export default function createIntegration(args?: Options): AstroIntegration {
317291
};
318292
}
319293
},
320-
'astro:build:done': async ({ pages, dir, logger, assets }) => {
294+
'astro:build:done': async ({ dir, logger, assets }) => {
321295
let redirectsExists = false;
322296
try {
323297
const redirectsStat = await stat(new URL('./_redirects', _config.build.client));
@@ -353,28 +327,6 @@ export default function createIntegration(args?: Options): AstroIntegration {
353327
}
354328
}
355329

356-
let routesExists = false;
357-
try {
358-
const routesStat = await stat(new URL('./_routes.json', _config.build.client));
359-
if (routesStat.isFile()) {
360-
routesExists = true;
361-
}
362-
} catch (_error) {
363-
routesExists = false;
364-
}
365-
366-
if (!routesExists) {
367-
await createRoutesFile(
368-
_config,
369-
logger,
370-
_routes,
371-
pages,
372-
redirects,
373-
args?.routes?.extend?.include,
374-
args?.routes?.extend?.exclude,
375-
);
376-
}
377-
378330
const trueRedirects = createRedirectsFromAstroRoutes({
379331
config: _config,
380332
routeToDynamicTargetMap: new Map(

0 commit comments

Comments
 (0)