@astrojs/cloudflare 9.2.0 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1,3 @@
1
1
  export {};
2
+ // NOTE: this file is empty on purpose
3
+ // it allows use to offer `imageService: 'compile'`
@@ -1,5 +1,6 @@
1
+ import { joinPaths } from '@astrojs/internal-helpers/path';
1
2
  import { baseService } from 'astro/assets';
2
- import { isESMImportedImage, isRemoteAllowed, joinPaths } from '../utils/assets.js';
3
+ import { isESMImportedImage, isRemoteAllowed } from '../utils/assets.js';
3
4
  const service = {
4
5
  ...baseService,
5
6
  getURL: (options, imageConfig) => {
@@ -1,21 +1,22 @@
1
- import type { Request as CFRequest, CacheStorage, ExecutionContext } from '@cloudflare/workers-types';
1
+ import type { CacheStorage as CLOUDFLARE_CACHESTORAGE, Request as CLOUDFLARE_REQUEST, ExecutionContext } from '@cloudflare/workers-types';
2
2
  import type { SSRManifest } from 'astro';
3
3
  type Env = {
4
4
  ASSETS: {
5
- fetch: (req: Request) => Promise<Response>;
5
+ fetch: (req: Request | string) => Promise<Response>;
6
6
  };
7
+ ASTRO_STUDIO_APP_TOKEN?: string;
7
8
  };
8
- export interface AdvancedRuntime<T extends object = object> {
9
+ export interface Runtime<T extends object = object> {
9
10
  runtime: {
10
11
  waitUntil: (promise: Promise<any>) => void;
11
12
  env: Env & T;
12
- cf: CFRequest['cf'];
13
- caches: CacheStorage;
13
+ cf: CLOUDFLARE_REQUEST['cf'];
14
+ caches: CLOUDFLARE_CACHESTORAGE;
14
15
  };
15
16
  }
16
17
  export declare function createExports(manifest: SSRManifest): {
17
18
  default: {
18
- fetch: (request: Request & CFRequest, env: Env, context: ExecutionContext) => Promise<Response>;
19
+ fetch: (request: Request & CLOUDFLARE_REQUEST, env: Env, context: ExecutionContext) => Promise<Response>;
19
20
  };
20
21
  };
21
22
  export {};
@@ -1,21 +1,26 @@
1
1
  import { App } from 'astro/app';
2
- import { getProcessEnvProxy, isNode } from '../util.js';
3
- if (!isNode) {
4
- process.env = getProcessEnvProxy();
5
- }
6
2
  export function createExports(manifest) {
7
3
  const app = new App(manifest);
8
4
  const fetch = async (request, env, context) => {
9
- // TODO: remove this any cast in the future
10
- // REF: the type cast to any is needed because the Cloudflare Env Type is not assignable to type 'ProcessEnv'
11
- process.env = env;
12
5
  const { pathname } = new URL(request.url);
13
6
  // static assets fallback, in case default _routes.json is not used
14
7
  if (manifest.assets.has(pathname)) {
15
- return env.ASSETS.fetch(request);
8
+ return env.ASSETS.fetch(request.url.replace(/\.html$/, ''));
16
9
  }
17
10
  const routeData = app.match(request);
11
+ if (!routeData) {
12
+ // https://developers.cloudflare.com/pages/functions/api-reference/#envassetsfetch
13
+ const asset = await env.ASSETS.fetch(request.url.replace(/index.html$/, '').replace(/\.html$/, ''));
14
+ if (asset.status !== 404) {
15
+ return asset;
16
+ }
17
+ }
18
18
  Reflect.set(request, Symbol.for('astro.clientAddress'), request.headers.get('cf-connecting-ip'));
19
+ process.env.ASTRO_STUDIO_APP_TOKEN ??= (() => {
20
+ if (typeof env.ASTRO_STUDIO_APP_TOKEN === 'string') {
21
+ return env.ASTRO_STUDIO_APP_TOKEN;
22
+ }
23
+ })();
19
24
  const locals = {
20
25
  runtime: {
21
26
  waitUntil: (promise) => {
package/dist/index.d.ts CHANGED
@@ -1,60 +1,48 @@
1
1
  import type { AstroIntegration } from 'astro';
2
- import type { RUNTIME } from './utils/local-runtime.js';
3
- export type { AdvancedRuntime } from './entrypoints/server.advanced.js';
4
- export type { DirectoryRuntime } from './entrypoints/server.directory.js';
2
+ export type { Runtime } from './entrypoints/server.advanced.js';
5
3
  export type Options = {
6
- /**
7
- * @deprecated Removed in v10. The 'directory' mode was discontinued because it redundantly bundles code, slowing down your site. Prefer using Astro API Endpoints over `/functions`. The new default mode is 'advanced'.
8
- */
9
- mode?: 'directory' | 'advanced';
10
- /**
11
- * @deprecated Removed in v10. This setting is obsolete as Cloudflare handles all functions in a single execution context, negating the need for multiple functions per project.
12
- */
13
- functionPerRoute?: boolean;
4
+ /** Options for handling images. */
14
5
  imageService?: 'passthrough' | 'cloudflare' | 'compile';
6
+ /** Configuration for `_routes.json` generation. A _routes.json file controls when your Function is invoked. This file will include three different properties:
7
+ *
8
+ * - 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.
9
+ * - include: Defines routes that will be invoked by Functions. Accepts wildcard behavior.
10
+ * - exclude: Defines routes that will not be invoked by Functions. Accepts wildcard behavior. `exclude` always take priority over `include`.
11
+ *
12
+ * Wildcards match any number of path segments (slashes). For example, `/users/*` will match everything after the `/users/` path.
13
+ *
14
+ */
15
15
  routes?: {
16
- /**
17
- * @deprecated Removed in v10. You will have two options going forward, using auto generated `_route.json` file or provide your own one in `public/_routes.json`. The previous method caused confusion and inconsistencies.
18
- */
19
- strategy?: 'auto' | 'include' | 'exclude';
20
- /**
21
- * @deprecated Removed in v10. Use `routes.extend.include` instead.
22
- */
23
- include?: string[];
24
- /**
25
- * @deprecated Removed in v10. Use `routes.extend.exclude` instead.
26
- */
27
- exclude?: string[];
16
+ /** Extend `_routes.json` */
17
+ extend: {
18
+ /** Paths which should be routed to the SSR function */
19
+ include?: {
20
+ /** Generally this is in pathname format, but does support wildcards, e.g. `/users`, `/products/*` */
21
+ pattern: string;
22
+ }[];
23
+ /** Paths which should be routed as static assets */
24
+ exclude?: {
25
+ /** Generally this is in pathname format, but does support wildcards, e.g. `/static`, `/assets/*`, `/images/avatar.jpg` */
26
+ pattern: string;
27
+ }[];
28
+ };
28
29
  };
29
30
  /**
30
- * @deprecated Removed in v10. Configure bindings in `wrangler.toml`. Leveraging Cloudflare's API simplifies setup and ensures full compatibility with Wrangler configurations. Use `platformProxy` instead.
31
+ * Proxy configuration for the platform.
31
32
  */
32
- runtime?: {
33
- mode: 'off';
34
- } | {
35
- mode: Extract<RUNTIME, {
36
- type: 'pages';
37
- }>['mode'];
38
- type: Extract<RUNTIME, {
39
- type: 'pages';
40
- }>['type'];
41
- persistTo?: Extract<RUNTIME, {
42
- type: 'pages';
43
- }>['persistTo'];
44
- bindings?: Extract<RUNTIME, {
45
- type: 'pages';
46
- }>['bindings'];
47
- } | {
48
- mode: Extract<RUNTIME, {
49
- type: 'workers';
50
- }>['mode'];
51
- type: Extract<RUNTIME, {
52
- type: 'workers';
53
- }>['type'];
54
- persistTo?: Extract<RUNTIME, {
55
- type: 'workers';
56
- }>['persistTo'];
33
+ platformProxy?: {
34
+ /** Toggle the proxy. Default `undefined`, which equals to `false`. */
35
+ enabled?: boolean;
36
+ /** Path to the configuration file. Default `wrangler.toml`. */
37
+ configPath?: string;
38
+ /** Enable experimental support for JSON configuration. Default `false`. */
39
+ experimentalJsonConfig?: boolean;
40
+ /** Configuration persistence settings. Default '.wrangler/state/v3' */
41
+ persist?: boolean | {
42
+ path: string;
43
+ };
57
44
  };
45
+ /** Enable WebAssembly support */
58
46
  wasmModuleImports?: boolean;
59
47
  };
60
48
  export default function createIntegration(args?: Options): AstroIntegration;