@astrojs/cloudflare 7.5.2 → 7.5.4
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/README.md +2 -2
- package/dist/entrypoints/server.advanced.d.ts +2 -2
- package/dist/entrypoints/server.advanced.js +39 -43
- package/dist/entrypoints/server.directory.d.ts +2 -2
- package/dist/entrypoints/server.directory.js +41 -45
- package/dist/getAdapter.js +26 -32
- package/dist/index.js +476 -423
- package/dist/util.js +12 -17
- package/dist/utils/deduplicatePatterns.js +22 -14
- package/dist/utils/getCFObject.js +64 -65
- package/dist/utils/parser.js +129 -124
- package/dist/utils/prependForwardSlash.js +2 -5
- package/dist/utils/rewriteWasmImportPath.js +22 -24
- package/dist/utils/wasm-module-loader.js +92 -79
- package/package.json +16 -17
- package/LICENSE +0 -61
package/README.md
CHANGED
|
@@ -169,7 +169,7 @@ default: `false`
|
|
|
169
169
|
|
|
170
170
|
Whether or not to import `.wasm` files [directly as ES modules](https://github.com/WebAssembly/esm-integration/tree/main/proposals/esm-integration) using the `.wasm?module` import syntax.
|
|
171
171
|
|
|
172
|
-
Add `wasmModuleImports: true` to `astro.config.mjs` to enable this functionality in both the Cloudflare build and the Astro dev server. Read more about [using Wasm modules](#use-wasm-modules)
|
|
172
|
+
Add `wasmModuleImports: true` to `astro.config.mjs` to enable this functionality in both the Cloudflare build and the Astro dev server. Read more about [using Wasm modules](#use-wasm-modules).
|
|
173
173
|
|
|
174
174
|
```diff lang="js"
|
|
175
175
|
// astro.config.mjs
|
|
@@ -221,7 +221,7 @@ Currently supported bindings:
|
|
|
221
221
|
- [Cloudflare Workers KV](https://developers.cloudflare.com/kv/)
|
|
222
222
|
- [Cloudflare Durable Objects](https://developers.cloudflare.com/durable-objects/)
|
|
223
223
|
|
|
224
|
-
You can access the runtime from Astro components through `Astro.locals` inside any
|
|
224
|
+
You can access the runtime from Astro components through `Astro.locals` inside any `.astro` file.
|
|
225
225
|
|
|
226
226
|
```astro
|
|
227
227
|
---
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Request as CFRequest
|
|
1
|
+
import type { CacheStorage, ExecutionContext, Request as CFRequest } from '@cloudflare/workers-types';
|
|
2
2
|
import type { SSRManifest } from 'astro';
|
|
3
3
|
type Env = {
|
|
4
4
|
ASSETS: {
|
|
@@ -10,7 +10,7 @@ export interface AdvancedRuntime<T extends object = object> {
|
|
|
10
10
|
waitUntil: (promise: Promise<any>) => void;
|
|
11
11
|
env: Env & T;
|
|
12
12
|
cf: CFRequest['cf'];
|
|
13
|
-
caches:
|
|
13
|
+
caches: CacheStorage;
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
16
|
export declare function createExports(manifest: SSRManifest): {
|
|
@@ -1,48 +1,44 @@
|
|
|
1
|
-
import { App } from
|
|
2
|
-
import { getProcessEnvProxy, isNode } from
|
|
1
|
+
import { App } from 'astro/app';
|
|
2
|
+
import { getProcessEnvProxy, isNode } from '../util.js';
|
|
3
3
|
if (!isNode) {
|
|
4
|
-
|
|
4
|
+
process.env = getProcessEnvProxy();
|
|
5
5
|
}
|
|
6
|
-
function createExports(manifest) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
Reflect.set(
|
|
17
|
-
request,
|
|
18
|
-
Symbol.for("astro.clientAddress"),
|
|
19
|
-
request.headers.get("cf-connecting-ip")
|
|
20
|
-
);
|
|
21
|
-
const locals = {
|
|
22
|
-
runtime: {
|
|
23
|
-
waitUntil: (promise) => {
|
|
24
|
-
context.waitUntil(promise);
|
|
25
|
-
},
|
|
26
|
-
env,
|
|
27
|
-
cf: request.cf,
|
|
28
|
-
caches
|
|
6
|
+
export function createExports(manifest) {
|
|
7
|
+
const app = new App(manifest);
|
|
8
|
+
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
|
+
const { pathname } = new URL(request.url);
|
|
13
|
+
// static assets fallback, in case default _routes.json is not used
|
|
14
|
+
if (manifest.assets.has(pathname)) {
|
|
15
|
+
return env.ASSETS.fetch(request);
|
|
29
16
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
17
|
+
let routeData = app.match(request, { matchNotFound: true });
|
|
18
|
+
if (routeData) {
|
|
19
|
+
Reflect.set(request, Symbol.for('astro.clientAddress'), request.headers.get('cf-connecting-ip'));
|
|
20
|
+
const locals = {
|
|
21
|
+
runtime: {
|
|
22
|
+
waitUntil: (promise) => {
|
|
23
|
+
context.waitUntil(promise);
|
|
24
|
+
},
|
|
25
|
+
env: env,
|
|
26
|
+
cf: request.cf,
|
|
27
|
+
caches: caches,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
let response = await app.render(request, routeData, locals);
|
|
31
|
+
if (app.setCookieHeaders) {
|
|
32
|
+
for (const setCookieHeader of app.setCookieHeaders(response)) {
|
|
33
|
+
response.headers.append('Set-Cookie', setCookieHeader);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return response;
|
|
35
37
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
return { default: { fetch } };
|
|
38
|
+
return new Response(null, {
|
|
39
|
+
status: 404,
|
|
40
|
+
statusText: 'Not found',
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
return { default: { fetch } };
|
|
45
44
|
}
|
|
46
|
-
export {
|
|
47
|
-
createExports
|
|
48
|
-
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { Request as CFRequest
|
|
1
|
+
import type { CacheStorage, EventContext, Request as CFRequest } from '@cloudflare/workers-types';
|
|
2
2
|
import type { SSRManifest } from 'astro';
|
|
3
3
|
export interface DirectoryRuntime<T extends object = object> {
|
|
4
4
|
runtime: {
|
|
5
5
|
waitUntil: (promise: Promise<any>) => void;
|
|
6
6
|
env: EventContext<unknown, string, unknown>['env'] & T;
|
|
7
7
|
cf: CFRequest['cf'];
|
|
8
|
-
caches:
|
|
8
|
+
caches: CacheStorage;
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
11
|
export declare function createExports(manifest: SSRManifest): {
|
|
@@ -1,50 +1,46 @@
|
|
|
1
|
-
import { App } from
|
|
2
|
-
import { getProcessEnvProxy, isNode } from
|
|
1
|
+
import { App } from 'astro/app';
|
|
2
|
+
import { getProcessEnvProxy, isNode } from '../util.js';
|
|
3
3
|
if (!isNode) {
|
|
4
|
-
|
|
4
|
+
process.env = getProcessEnvProxy();
|
|
5
5
|
}
|
|
6
|
-
function createExports(manifest) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
Reflect.set(
|
|
19
|
-
request,
|
|
20
|
-
Symbol.for("astro.clientAddress"),
|
|
21
|
-
request.headers.get("cf-connecting-ip")
|
|
22
|
-
);
|
|
23
|
-
const locals = {
|
|
24
|
-
runtime: {
|
|
25
|
-
waitUntil: (promise) => {
|
|
26
|
-
context.waitUntil(promise);
|
|
27
|
-
},
|
|
28
|
-
env: context.env,
|
|
29
|
-
cf: request.cf,
|
|
30
|
-
caches
|
|
6
|
+
export function createExports(manifest) {
|
|
7
|
+
const app = new App(manifest);
|
|
8
|
+
const onRequest = async (context) => {
|
|
9
|
+
const request = context.request;
|
|
10
|
+
const { env } = context;
|
|
11
|
+
// TODO: remove this any cast in the future
|
|
12
|
+
// REF: the type cast to any is needed because the Cloudflare Env Type is not assignable to type 'ProcessEnv'
|
|
13
|
+
process.env = env;
|
|
14
|
+
const { pathname } = new URL(request.url);
|
|
15
|
+
// static assets fallback, in case default _routes.json is not used
|
|
16
|
+
if (manifest.assets.has(pathname)) {
|
|
17
|
+
return env.ASSETS.fetch(request);
|
|
31
18
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
19
|
+
let routeData = app.match(request, { matchNotFound: true });
|
|
20
|
+
if (routeData) {
|
|
21
|
+
Reflect.set(request, Symbol.for('astro.clientAddress'), request.headers.get('cf-connecting-ip'));
|
|
22
|
+
const locals = {
|
|
23
|
+
runtime: {
|
|
24
|
+
waitUntil: (promise) => {
|
|
25
|
+
context.waitUntil(promise);
|
|
26
|
+
},
|
|
27
|
+
env: context.env,
|
|
28
|
+
cf: request.cf,
|
|
29
|
+
caches: caches,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
let response = await app.render(request, routeData, locals);
|
|
33
|
+
if (app.setCookieHeaders) {
|
|
34
|
+
for (const setCookieHeader of app.setCookieHeaders(response)) {
|
|
35
|
+
response.headers.append('Set-Cookie', setCookieHeader);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return response;
|
|
37
39
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
return { onRequest, manifest };
|
|
40
|
+
return new Response(null, {
|
|
41
|
+
status: 404,
|
|
42
|
+
statusText: 'Not found',
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
return { onRequest, manifest };
|
|
47
46
|
}
|
|
48
|
-
export {
|
|
49
|
-
createExports
|
|
50
|
-
};
|
package/dist/getAdapter.js
CHANGED
|
@@ -1,36 +1,30 @@
|
|
|
1
|
-
function getAdapter({
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
export function getAdapter({ isModeDirectory, functionPerRoute, }) {
|
|
2
|
+
const astroFeatures = {
|
|
3
|
+
hybridOutput: 'stable',
|
|
4
|
+
staticOutput: 'unsupported',
|
|
5
|
+
serverOutput: 'stable',
|
|
6
|
+
assets: {
|
|
7
|
+
supportKind: 'stable',
|
|
8
|
+
isSharpCompatible: false,
|
|
9
|
+
isSquooshCompatible: false,
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
if (isModeDirectory) {
|
|
13
|
+
return {
|
|
14
|
+
name: '@astrojs/cloudflare',
|
|
15
|
+
serverEntrypoint: '@astrojs/cloudflare/entrypoints/server.directory.js',
|
|
16
|
+
exports: ['onRequest', 'manifest'],
|
|
17
|
+
adapterFeatures: {
|
|
18
|
+
functionPerRoute,
|
|
19
|
+
edgeMiddleware: false,
|
|
20
|
+
},
|
|
21
|
+
supportedAstroFeatures: astroFeatures,
|
|
22
|
+
};
|
|
13
23
|
}
|
|
14
|
-
};
|
|
15
|
-
if (isModeDirectory) {
|
|
16
24
|
return {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
functionPerRoute,
|
|
22
|
-
edgeMiddleware: false
|
|
23
|
-
},
|
|
24
|
-
supportedAstroFeatures: astroFeatures
|
|
25
|
+
name: '@astrojs/cloudflare',
|
|
26
|
+
serverEntrypoint: '@astrojs/cloudflare/entrypoints/server.advanced.js',
|
|
27
|
+
exports: ['default'],
|
|
28
|
+
supportedAstroFeatures: astroFeatures,
|
|
25
29
|
};
|
|
26
|
-
}
|
|
27
|
-
return {
|
|
28
|
-
name: "@astrojs/cloudflare",
|
|
29
|
-
serverEntrypoint: "@astrojs/cloudflare/entrypoints/server.advanced.js",
|
|
30
|
-
exports: ["default"],
|
|
31
|
-
supportedAstroFeatures: astroFeatures
|
|
32
|
-
};
|
|
33
30
|
}
|
|
34
|
-
export {
|
|
35
|
-
getAdapter
|
|
36
|
-
};
|