@astrojs/cloudflare 9.2.1 → 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.
- package/dist/entrypoints/image-endpoint.js +2 -0
- package/dist/entrypoints/image-service.js +2 -1
- package/dist/entrypoints/server.advanced.d.ts +7 -6
- package/dist/entrypoints/server.advanced.js +13 -8
- package/dist/index.d.ts +37 -49
- package/dist/index.js +123 -374
- package/dist/utils/assets.d.ts +0 -5
- package/dist/utils/assets.js +1 -26
- package/dist/utils/generate-routes-json.d.ts +9 -0
- package/dist/utils/generate-routes-json.js +205 -0
- package/dist/utils/image-config.d.ts +1 -1
- package/dist/utils/image-config.js +1 -1
- package/dist/utils/wasm-module-loader.d.ts +1 -2
- package/dist/utils/wasm-module-loader.js +33 -19
- package/package.json +8 -12
- package/dist/entrypoints/server.directory.d.ts +0 -14
- package/dist/entrypoints/server.directory.js +0 -40
- package/dist/getAdapter.d.ts +0 -5
- package/dist/getAdapter.js +0 -30
- package/dist/util.d.ts +0 -2
- package/dist/util.js +0 -10
- package/dist/utils/deduplicatePatterns.d.ts +0 -8
- package/dist/utils/deduplicatePatterns.js +0 -25
- package/dist/utils/local-runtime.d.ts +0 -11744
- package/dist/utils/local-runtime.js +0 -250
- package/dist/utils/parser.d.ts +0 -27
- package/dist/utils/parser.js +0 -149
- package/dist/utils/prependForwardSlash.d.ts +0 -1
- package/dist/utils/prependForwardSlash.js +0 -3
- package/dist/utils/rewriteWasmImportPath.d.ts +0 -8
- package/dist/utils/rewriteWasmImportPath.js +0 -22
- package/dist/utils/sharpBundlePatch.d.ts +0 -2
- package/dist/utils/sharpBundlePatch.js +0 -17
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { joinPaths } from '@astrojs/internal-helpers/path';
|
|
1
2
|
import { baseService } from 'astro/assets';
|
|
2
|
-
import { isESMImportedImage, isRemoteAllowed
|
|
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 {
|
|
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
|
|
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:
|
|
13
|
-
caches:
|
|
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 &
|
|
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
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
*
|
|
31
|
+
* Proxy configuration for the platform.
|
|
31
32
|
*/
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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;
|