@astrojs/cloudflare 6.7.0 → 6.8.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/README.md +2 -4
- package/dist/runtime.d.ts +10 -0
- package/dist/server.advanced.js +11 -1
- package/dist/server.directory.d.ts +2 -6
- package/dist/server.directory.js +18 -12
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -73,12 +73,10 @@ It's then possible to update the preview script in your `package.json` to `"prev
|
|
|
73
73
|
|
|
74
74
|
## Access to the Cloudflare runtime
|
|
75
75
|
|
|
76
|
-
You can access all the Cloudflare bindings and environment variables from Astro components and API routes through
|
|
76
|
+
You can access all the Cloudflare bindings and environment variables from Astro components and API routes through `Astro.locals`.
|
|
77
77
|
|
|
78
78
|
```js
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
getRuntime(Astro.request);
|
|
79
|
+
const env = Astro.locals.runtime.env;
|
|
82
80
|
```
|
|
83
81
|
|
|
84
82
|
Depending on your adapter mode (advanced = worker, directory = pages), the runtime object will look a little different due to differences in the Cloudflare API.
|
package/dist/runtime.d.ts
CHANGED
|
@@ -22,4 +22,14 @@ export type PagesRuntime<T = unknown, U = unknown> = {
|
|
|
22
22
|
};
|
|
23
23
|
cf?: IncomingRequestCfProperties;
|
|
24
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* @deprecated since version 6.8.0
|
|
27
|
+
* The `getRuntime` utility has been deprecated and should be updated to the new [`Astro.locals`](https://docs.astro.build/en/guides/middleware/#locals) API.
|
|
28
|
+
* ```diff
|
|
29
|
+
* - import { getRuntime } from '@astrojs/cloudflare/runtime';
|
|
30
|
+
* - getRuntime(Astro.request);
|
|
31
|
+
*
|
|
32
|
+
* + const runtime = Astro.locals.runtime;
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
25
35
|
export declare function getRuntime<T = unknown, U = unknown>(request: Request): WorkerRuntime<T> | PagesRuntime<T, U>;
|
package/dist/server.advanced.js
CHANGED
|
@@ -28,7 +28,17 @@ function createExports(manifest) {
|
|
|
28
28
|
context.waitUntil(promise);
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
|
-
|
|
31
|
+
const locals = {
|
|
32
|
+
runtime: {
|
|
33
|
+
waitUntil: (promise) => {
|
|
34
|
+
context.waitUntil(promise);
|
|
35
|
+
},
|
|
36
|
+
env,
|
|
37
|
+
cf: request.cf,
|
|
38
|
+
caches
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
let response = await app.render(request, routeData, locals);
|
|
32
42
|
if (app.setCookieHeaders) {
|
|
33
43
|
for (const setCookieHeader of app.setCookieHeaders(response)) {
|
|
34
44
|
response.headers.append("Set-Cookie", setCookieHeader);
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { EventContext } from '@cloudflare/workers-types';
|
|
2
2
|
import type { SSRManifest } from 'astro';
|
|
3
3
|
export declare function createExports(manifest: SSRManifest): {
|
|
4
|
-
onRequest: (
|
|
5
|
-
request: Request & CFRequest;
|
|
6
|
-
next: (request: Request) => void;
|
|
7
|
-
waitUntil: EventContext<unknown, any, unknown>['waitUntil'];
|
|
8
|
-
} & Record<string, unknown>) => Promise<import("@cloudflare/workers-types").Response | Response>;
|
|
4
|
+
onRequest: (context: EventContext<unknown, string, unknown>) => Promise<import("@cloudflare/workers-types").Response | Response>;
|
|
9
5
|
manifest: SSRManifest;
|
|
10
6
|
};
|
package/dist/server.directory.js
CHANGED
|
@@ -5,17 +5,13 @@ if (!isNode) {
|
|
|
5
5
|
}
|
|
6
6
|
function createExports(manifest) {
|
|
7
7
|
const app = new App(manifest);
|
|
8
|
-
const onRequest = async ({
|
|
9
|
-
request
|
|
10
|
-
next,
|
|
11
|
-
|
|
12
|
-
}) => {
|
|
13
|
-
process.env = runtimeEnv.env;
|
|
8
|
+
const onRequest = async (context) => {
|
|
9
|
+
const request = context.request;
|
|
10
|
+
const { next, env } = context;
|
|
11
|
+
process.env = env;
|
|
14
12
|
const { pathname } = new URL(request.url);
|
|
15
13
|
if (manifest.assets.has(pathname)) {
|
|
16
|
-
return
|
|
17
|
-
request
|
|
18
|
-
);
|
|
14
|
+
return env.ASSETS.fetch(request);
|
|
19
15
|
}
|
|
20
16
|
let routeData = app.match(request, { matchNotFound: true });
|
|
21
17
|
if (routeData) {
|
|
@@ -25,16 +21,26 @@ function createExports(manifest) {
|
|
|
25
21
|
request.headers.get("cf-connecting-ip")
|
|
26
22
|
);
|
|
27
23
|
Reflect.set(request, Symbol.for("runtime"), {
|
|
28
|
-
...
|
|
24
|
+
...context,
|
|
29
25
|
waitUntil: (promise) => {
|
|
30
|
-
|
|
26
|
+
context.waitUntil(promise);
|
|
31
27
|
},
|
|
32
28
|
name: "cloudflare",
|
|
33
29
|
next,
|
|
34
30
|
caches,
|
|
35
31
|
cf: request.cf
|
|
36
32
|
});
|
|
37
|
-
|
|
33
|
+
const locals = {
|
|
34
|
+
runtime: {
|
|
35
|
+
waitUntil: (promise) => {
|
|
36
|
+
context.waitUntil(promise);
|
|
37
|
+
},
|
|
38
|
+
env: context.env,
|
|
39
|
+
cf: request.cf,
|
|
40
|
+
caches
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
let response = await app.render(request, routeData, locals);
|
|
38
44
|
if (app.setCookieHeaders) {
|
|
39
45
|
for (const setCookieHeader of app.setCookieHeaders(response)) {
|
|
40
46
|
response.headers.append("Set-Cookie", setCookieHeader);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/cloudflare",
|
|
3
3
|
"description": "Deploy your site to Cloudflare Workers/Pages",
|
|
4
|
-
"version": "6.
|
|
4
|
+
"version": "6.8.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"author": "withastro",
|
|
@@ -38,14 +38,14 @@
|
|
|
38
38
|
"tiny-glob": "^0.2.9"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"astro": "^2.10.
|
|
41
|
+
"astro": "^2.10.6"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"chai": "^4.3.7",
|
|
45
45
|
"cheerio": "1.0.0-rc.12",
|
|
46
46
|
"mocha": "^9.2.2",
|
|
47
47
|
"wrangler": "^2.0.23",
|
|
48
|
-
"astro": "2.10.
|
|
48
|
+
"astro": "2.10.6",
|
|
49
49
|
"astro-scripts": "0.0.14"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|