@astrojs/cloudflare 12.6.2 → 12.6.3
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/index.js +14 -26
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { createReadStream } from "node:fs";
|
|
|
2
2
|
import { appendFile, stat } from "node:fs/promises";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { createInterface } from "node:readline/promises";
|
|
5
|
-
import {
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
6
|
import {
|
|
7
7
|
appendForwardSlash,
|
|
8
8
|
prependForwardSlash,
|
|
@@ -39,6 +39,7 @@ function createIntegration(args) {
|
|
|
39
39
|
args?.cloudflareModules ?? true
|
|
40
40
|
);
|
|
41
41
|
let _routes;
|
|
42
|
+
const SESSION_KV_BINDING_NAME = args?.sessionKVBindingName ?? "SESSION";
|
|
42
43
|
return {
|
|
43
44
|
name: "@astrojs/cloudflare",
|
|
44
45
|
hooks: {
|
|
@@ -48,34 +49,21 @@ function createIntegration(args) {
|
|
|
48
49
|
updateConfig,
|
|
49
50
|
logger,
|
|
50
51
|
addWatchFile,
|
|
51
|
-
addMiddleware
|
|
52
|
-
createCodegenDir
|
|
52
|
+
addMiddleware
|
|
53
53
|
}) => {
|
|
54
54
|
let session = config.session;
|
|
55
|
-
const isBuild = command === "build";
|
|
56
55
|
if (!session?.driver) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
`If you see the error "Invalid binding \`${bindingName}\`" in your build output, you need to add the binding to your wrangler config file.`
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
session = isBuild ? {
|
|
56
|
+
logger.info(
|
|
57
|
+
`Enabling sessions with Cloudflare KV with the "${SESSION_KV_BINDING_NAME}" KV binding.`
|
|
58
|
+
);
|
|
59
|
+
logger.info(
|
|
60
|
+
`If you see the error "Invalid binding \`${SESSION_KV_BINDING_NAME}\`" in your build output, you need to add the binding to your wrangler config file.`
|
|
61
|
+
);
|
|
62
|
+
session = {
|
|
68
63
|
...session,
|
|
69
64
|
driver: "cloudflare-kv-binding",
|
|
70
65
|
options: {
|
|
71
|
-
binding:
|
|
72
|
-
...session?.options
|
|
73
|
-
}
|
|
74
|
-
} : {
|
|
75
|
-
...session,
|
|
76
|
-
driver: "fs-lite",
|
|
77
|
-
options: {
|
|
78
|
-
base: fileURLToPath(new URL("sessions", sessionDir)),
|
|
66
|
+
binding: SESSION_KV_BINDING_NAME,
|
|
79
67
|
...session?.options
|
|
80
68
|
}
|
|
81
69
|
};
|
|
@@ -170,6 +158,8 @@ function createIntegration(args) {
|
|
|
170
158
|
await platformProxy.dispose();
|
|
171
159
|
});
|
|
172
160
|
setProcessEnv(_config, platformProxy.env);
|
|
161
|
+
globalThis.__env__ ??= {};
|
|
162
|
+
globalThis.__env__[SESSION_KV_BINDING_NAME] = platformProxy.env[SESSION_KV_BINDING_NAME];
|
|
173
163
|
const clientLocalsSymbol = Symbol.for("astro.locals");
|
|
174
164
|
server.middlewares.use(async function middleware(req, _res, next) {
|
|
175
165
|
Reflect.set(req, clientLocalsSymbol, {
|
|
@@ -222,9 +212,7 @@ function createIntegration(args) {
|
|
|
222
212
|
vite.define = {
|
|
223
213
|
"process.env": "process.env",
|
|
224
214
|
// Allows the request handler to know what the binding name is
|
|
225
|
-
"globalThis.__ASTRO_SESSION_BINDING_NAME": JSON.stringify(
|
|
226
|
-
args?.sessionKVBindingName ?? "SESSION"
|
|
227
|
-
),
|
|
215
|
+
"globalThis.__ASTRO_SESSION_BINDING_NAME": JSON.stringify(SESSION_KV_BINDING_NAME),
|
|
228
216
|
...vite.define
|
|
229
217
|
};
|
|
230
218
|
}
|
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.6.
|
|
4
|
+
"version": "12.6.3",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"author": "withastro",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"devalue": "^5.1.1",
|
|
46
46
|
"execa": "^8.0.1",
|
|
47
47
|
"rollup": "^4.40.2",
|
|
48
|
-
"astro": "5.12.
|
|
48
|
+
"astro": "5.12.9",
|
|
49
49
|
"astro-scripts": "0.0.14"
|
|
50
50
|
},
|
|
51
51
|
"publishConfig": {
|