@astrojs/cloudflare 12.3.0 → 12.4.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/server.d.ts +4 -0
- package/dist/entrypoints/server.js +3 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +35 -1
- package/package.json +7 -6
|
@@ -15,6 +15,10 @@ export interface Runtime<T extends object = object> {
|
|
|
15
15
|
ctx: ExecutionContext;
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
+
declare global {
|
|
19
|
+
var __ASTRO_SESSION_BINDING_NAME: string;
|
|
20
|
+
var __env__: Partial<Env>;
|
|
21
|
+
}
|
|
18
22
|
export declare function createExports(manifest: SSRManifest): {
|
|
19
23
|
default: {
|
|
20
24
|
fetch: (request: Request & CLOUDFLARE_REQUEST, env: Env, context: ExecutionContext) => Promise<Response>;
|
|
@@ -7,6 +7,9 @@ function createExports(manifest) {
|
|
|
7
7
|
const app = new App(manifest);
|
|
8
8
|
const fetch = async (request, env, context) => {
|
|
9
9
|
const { pathname } = new URL(request.url);
|
|
10
|
+
const bindingName = globalThis.__ASTRO_SESSION_BINDING_NAME;
|
|
11
|
+
globalThis.__env__ ??= {};
|
|
12
|
+
globalThis.__env__[bindingName] = env[bindingName];
|
|
10
13
|
if (manifest.assets.has(pathname)) {
|
|
11
14
|
return env.ASSETS.fetch(request.url.replace(/\.html$/, ""));
|
|
12
15
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -43,5 +43,31 @@ export type Options = {
|
|
|
43
43
|
* for reference on how these file types are exported
|
|
44
44
|
*/
|
|
45
45
|
cloudflareModules?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* By default, Astro will be configured to use Cloudflare KV to store session data. If you want to use sessions,
|
|
48
|
+
* you must create a KV namespace and declare it in your wrangler config file. You can do this with the wrangler command:
|
|
49
|
+
*
|
|
50
|
+
* ```sh
|
|
51
|
+
* npx wrangler kv namespace create SESSION
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* This will log the id of the created namespace. You can then add it to your `wrangler.json` file like this:
|
|
55
|
+
*
|
|
56
|
+
* ```json
|
|
57
|
+
* {
|
|
58
|
+
* "kv_namespaces": [
|
|
59
|
+
* {
|
|
60
|
+
* "binding": "SESSION",
|
|
61
|
+
* "id": "<your kv namespace id here>"
|
|
62
|
+
* }
|
|
63
|
+
* ]
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
66
|
+
* By default, the driver looks for the binding named `SESSION`, but you can override this by providing a different name here.
|
|
67
|
+
*
|
|
68
|
+
* See https://developers.cloudflare.com/kv/concepts/kv-namespaces/ for more details on using KV namespaces.
|
|
69
|
+
*
|
|
70
|
+
*/
|
|
71
|
+
sessionKVBindingName?: string;
|
|
46
72
|
};
|
|
47
73
|
export default function createIntegration(args?: Options): AstroIntegration;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createReadStream } from "node:fs";
|
|
2
2
|
import { appendFile, stat } from "node:fs/promises";
|
|
3
3
|
import { createInterface } from "node:readline/promises";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
4
5
|
import {
|
|
5
6
|
appendForwardSlash,
|
|
6
7
|
prependForwardSlash,
|
|
@@ -46,8 +47,36 @@ function createIntegration(args) {
|
|
|
46
47
|
updateConfig,
|
|
47
48
|
logger,
|
|
48
49
|
addWatchFile,
|
|
49
|
-
addMiddleware
|
|
50
|
+
addMiddleware,
|
|
51
|
+
createCodegenDir
|
|
50
52
|
}) => {
|
|
53
|
+
let session = config.session;
|
|
54
|
+
const isBuild = command === "build";
|
|
55
|
+
if (config.experimental.session && !session?.driver) {
|
|
56
|
+
const sessionDir = isBuild ? void 0 : createCodegenDir();
|
|
57
|
+
const bindingName = args?.sessionKVBindingName ?? "SESSION";
|
|
58
|
+
logger.info(
|
|
59
|
+
`Configuring experimental session support using ${isBuild ? "Cloudflare KV" : "filesystem storage"}. Be sure to define a KV binding named "${bindingName}".`
|
|
60
|
+
);
|
|
61
|
+
logger.info(
|
|
62
|
+
`If you see the error "Invalid binding \`${bindingName}\`" in your build output, you need to add the binding to your wrangler config file.`
|
|
63
|
+
);
|
|
64
|
+
session = isBuild ? {
|
|
65
|
+
...session,
|
|
66
|
+
driver: "cloudflare-kv-binding",
|
|
67
|
+
options: {
|
|
68
|
+
binding: bindingName,
|
|
69
|
+
...session?.options
|
|
70
|
+
}
|
|
71
|
+
} : {
|
|
72
|
+
...session,
|
|
73
|
+
driver: "fs-lite",
|
|
74
|
+
options: {
|
|
75
|
+
base: fileURLToPath(new URL("sessions", sessionDir)),
|
|
76
|
+
...session?.options
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
51
80
|
updateConfig({
|
|
52
81
|
build: {
|
|
53
82
|
client: new URL(`.${wrapWithSlashes(config.base)}`, config.outDir),
|
|
@@ -55,6 +84,7 @@ function createIntegration(args) {
|
|
|
55
84
|
serverEntry: "index.js",
|
|
56
85
|
redirects: false
|
|
57
86
|
},
|
|
87
|
+
session,
|
|
58
88
|
vite: {
|
|
59
89
|
plugins: [
|
|
60
90
|
// https://developers.cloudflare.com/pages/functions/module-support/
|
|
@@ -173,6 +203,10 @@ function createIntegration(args) {
|
|
|
173
203
|
vite.build.rollupOptions.output.banner ||= "globalThis.process ??= {}; globalThis.process.env ??= {};";
|
|
174
204
|
vite.define = {
|
|
175
205
|
"process.env": "process.env",
|
|
206
|
+
// Allows the request handler to know what the binding name is
|
|
207
|
+
"globalThis.__ASTRO_SESSION_BINDING_NAME": JSON.stringify(
|
|
208
|
+
args?.sessionKVBindingName ?? "SESSION"
|
|
209
|
+
),
|
|
176
210
|
...vite.define
|
|
177
211
|
};
|
|
178
212
|
}
|
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": "12.
|
|
4
|
+
"version": "12.4.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"author": "withastro",
|
|
@@ -29,14 +29,14 @@
|
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@cloudflare/workers-types": "^4.
|
|
32
|
+
"@cloudflare/workers-types": "^4.20250327.0",
|
|
33
33
|
"esbuild": "^0.25.0",
|
|
34
34
|
"estree-walker": "^3.0.3",
|
|
35
35
|
"magic-string": "^0.30.17",
|
|
36
|
-
"miniflare": "^4.
|
|
36
|
+
"miniflare": "^4.20250321.1",
|
|
37
37
|
"tinyglobby": "^0.2.12",
|
|
38
|
-
"vite": "^6.2.
|
|
39
|
-
"wrangler": "^4.
|
|
38
|
+
"vite": "^6.2.4",
|
|
39
|
+
"wrangler": "^4.5.1",
|
|
40
40
|
"@astrojs/internal-helpers": "0.6.1",
|
|
41
41
|
"@astrojs/underscore-redirects": "0.6.0"
|
|
42
42
|
},
|
|
@@ -45,10 +45,11 @@
|
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"cheerio": "1.0.0",
|
|
48
|
+
"devalue": "^5.1.1",
|
|
48
49
|
"execa": "^8.0.1",
|
|
49
50
|
"rollup": "^4.35.0",
|
|
50
51
|
"strip-ansi": "^7.1.0",
|
|
51
|
-
"astro": "5.5.
|
|
52
|
+
"astro": "5.5.6",
|
|
52
53
|
"astro-scripts": "0.0.14"
|
|
53
54
|
},
|
|
54
55
|
"publishConfig": {
|