@astrojs/cloudflare 6.3.0 → 6.5.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/index.js +16 -2
- package/dist/runtime.d.ts +9 -0
- package/dist/server.advanced.d.ts +2 -1
- package/dist/server.advanced.js +7 -1
- package/dist/server.directory.d.ts +2 -1
- package/dist/server.directory.js +3 -1
- package/package.json +5 -3
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createRedirectsFromAstroRoutes } from "@astrojs/underscore-redirects";
|
|
1
2
|
import esbuild from "esbuild";
|
|
2
3
|
import * as fs from "fs";
|
|
3
4
|
import * as os from "os";
|
|
@@ -31,7 +32,8 @@ function createIntegration(args) {
|
|
|
31
32
|
build: {
|
|
32
33
|
client: new URL(`.${config.base}`, config.outDir),
|
|
33
34
|
server: new URL(`.${SERVER_BUILD_FOLDER}`, config.outDir),
|
|
34
|
-
serverEntry: "_worker.mjs"
|
|
35
|
+
serverEntry: "_worker.mjs",
|
|
36
|
+
redirects: false
|
|
35
37
|
}
|
|
36
38
|
});
|
|
37
39
|
},
|
|
@@ -66,7 +68,7 @@ function createIntegration(args) {
|
|
|
66
68
|
vite.ssr.target = "webworker";
|
|
67
69
|
}
|
|
68
70
|
},
|
|
69
|
-
"astro:build:done": async ({ pages }) => {
|
|
71
|
+
"astro:build:done": async ({ pages, routes, dir }) => {
|
|
70
72
|
var _a, _b;
|
|
71
73
|
const entryPath = fileURLToPath(new URL(_buildConfig.serverEntry, _buildConfig.server));
|
|
72
74
|
const entryUrl = new URL(_buildConfig.serverEntry, _config.outDir);
|
|
@@ -134,6 +136,18 @@ function createIntegration(args) {
|
|
|
134
136
|
staticPathList.push(...redirects);
|
|
135
137
|
}
|
|
136
138
|
}
|
|
139
|
+
const redirectRoutes = routes.filter((r) => r.type === "redirect");
|
|
140
|
+
const trueRedirects = createRedirectsFromAstroRoutes({
|
|
141
|
+
config: _config,
|
|
142
|
+
routes: redirectRoutes,
|
|
143
|
+
dir
|
|
144
|
+
});
|
|
145
|
+
if (!trueRedirects.empty()) {
|
|
146
|
+
await fs.promises.appendFile(
|
|
147
|
+
new URL("./_redirects", _config.outDir),
|
|
148
|
+
trueRedirects.print()
|
|
149
|
+
);
|
|
150
|
+
}
|
|
137
151
|
await fs.promises.writeFile(
|
|
138
152
|
new URL("./_routes.json", _config.outDir),
|
|
139
153
|
JSON.stringify(
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
import type { Cache, CacheStorage, IncomingRequestCfProperties } from '@cloudflare/workers-types';
|
|
1
2
|
export type WorkerRuntime<T = unknown> = {
|
|
2
3
|
name: 'cloudflare';
|
|
3
4
|
env: T;
|
|
4
5
|
waitUntil(promise: Promise<any>): void;
|
|
5
6
|
passThroughOnException(): void;
|
|
7
|
+
caches?: CacheStorage & {
|
|
8
|
+
default: Cache;
|
|
9
|
+
};
|
|
10
|
+
cf?: IncomingRequestCfProperties;
|
|
6
11
|
};
|
|
7
12
|
export type PagesRuntime<T = unknown, U = unknown> = {
|
|
8
13
|
name: 'cloudflare';
|
|
@@ -12,5 +17,9 @@ export type PagesRuntime<T = unknown, U = unknown> = {
|
|
|
12
17
|
data: U;
|
|
13
18
|
waitUntil(promise: Promise<any>): void;
|
|
14
19
|
next(request: Request): void;
|
|
20
|
+
caches?: CacheStorage & {
|
|
21
|
+
default: Cache;
|
|
22
|
+
};
|
|
23
|
+
cf?: IncomingRequestCfProperties;
|
|
15
24
|
};
|
|
16
25
|
export declare function getRuntime<T = unknown, U = unknown>(request: Request): WorkerRuntime<T> | PagesRuntime<T, U>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Request as CFRequest } from '@cloudflare/workers-types';
|
|
1
2
|
import type { SSRManifest } from 'astro';
|
|
2
3
|
type Env = {
|
|
3
4
|
ASSETS: {
|
|
@@ -7,7 +8,7 @@ type Env = {
|
|
|
7
8
|
};
|
|
8
9
|
export declare function createExports(manifest: SSRManifest): {
|
|
9
10
|
default: {
|
|
10
|
-
fetch: (request: Request, env: Env, context: any) => Promise<Response>;
|
|
11
|
+
fetch: (request: Request & CFRequest, env: Env, context: any) => Promise<Response>;
|
|
11
12
|
};
|
|
12
13
|
};
|
|
13
14
|
export {};
|
package/dist/server.advanced.js
CHANGED
|
@@ -18,7 +18,13 @@ function createExports(manifest) {
|
|
|
18
18
|
Symbol.for("astro.clientAddress"),
|
|
19
19
|
request.headers.get("cf-connecting-ip")
|
|
20
20
|
);
|
|
21
|
-
Reflect.set(request, Symbol.for("runtime"), {
|
|
21
|
+
Reflect.set(request, Symbol.for("runtime"), {
|
|
22
|
+
env,
|
|
23
|
+
name: "cloudflare",
|
|
24
|
+
caches,
|
|
25
|
+
cf: request.cf,
|
|
26
|
+
...context
|
|
27
|
+
});
|
|
22
28
|
let response = await app.render(request, routeData);
|
|
23
29
|
if (app.setCookieHeaders) {
|
|
24
30
|
for (const setCookieHeader of app.setCookieHeaders(response)) {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import type { Request as CFRequest } from '@cloudflare/workers-types';
|
|
1
2
|
import type { SSRManifest } from 'astro';
|
|
2
3
|
export declare function createExports(manifest: SSRManifest): {
|
|
3
4
|
onRequest: ({ request, next, ...runtimeEnv }: {
|
|
4
|
-
request: Request;
|
|
5
|
+
request: Request & CFRequest;
|
|
5
6
|
next: (request: Request) => void;
|
|
6
7
|
} & Record<string, unknown>) => Promise<void | Response>;
|
|
7
8
|
};
|
package/dist/server.directory.js
CHANGED
|
@@ -25,7 +25,9 @@ function createExports(manifest) {
|
|
|
25
25
|
Reflect.set(request, Symbol.for("runtime"), {
|
|
26
26
|
...runtimeEnv,
|
|
27
27
|
name: "cloudflare",
|
|
28
|
-
next
|
|
28
|
+
next,
|
|
29
|
+
caches,
|
|
30
|
+
cf: request.cf
|
|
29
31
|
});
|
|
30
32
|
let response = await app.render(request, routeData);
|
|
31
33
|
if (app.setCookieHeaders) {
|
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.5.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"author": "withastro",
|
|
@@ -32,11 +32,13 @@
|
|
|
32
32
|
"runtime.d.ts"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
+
"@astrojs/underscore-redirects": "^0.1.0",
|
|
36
|
+
"@cloudflare/workers-types": "^4.20230518.0",
|
|
35
37
|
"esbuild": "^0.17.12",
|
|
36
38
|
"tiny-glob": "^0.2.9"
|
|
37
39
|
},
|
|
38
40
|
"peerDependencies": {
|
|
39
|
-
"astro": "^2.
|
|
41
|
+
"astro": "^2.6.4"
|
|
40
42
|
},
|
|
41
43
|
"devDependencies": {
|
|
42
44
|
"chai": "^4.3.6",
|
|
@@ -44,7 +46,7 @@
|
|
|
44
46
|
"mocha": "^9.2.2",
|
|
45
47
|
"slash": "^4.0.0",
|
|
46
48
|
"wrangler": "^2.0.23",
|
|
47
|
-
"astro": "2.
|
|
49
|
+
"astro": "2.6.4",
|
|
48
50
|
"astro-scripts": "0.0.14"
|
|
49
51
|
},
|
|
50
52
|
"scripts": {
|