@astrojs/cloudflare 1.0.2 → 2.1.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/.turbo/turbo-build.log +2 -2
- package/CHANGELOG.md +55 -0
- package/README.md +35 -2
- package/dist/index.js +5 -3
- package/dist/server.advanced.js +7 -1
- package/dist/server.directory.js +7 -1
- package/package.json +6 -3
- package/src/index.ts +4 -2
- package/src/server.advanced.ts +9 -1
- package/src/server.directory.ts +9 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
[33m@astrojs/cloudflare:build: [0mcache hit, replaying output [
|
|
1
|
+
[33m@astrojs/cloudflare:build: [0mcache hit, replaying output [2mf779b2bf8afec1e9[0m
|
|
2
2
|
[33m@astrojs/cloudflare:build: [0m
|
|
3
|
-
[33m@astrojs/cloudflare:build: [0m> @astrojs/cloudflare@1.0
|
|
3
|
+
[33m@astrojs/cloudflare:build: [0m> @astrojs/cloudflare@2.1.0 build /home/runner/work/astro/astro/packages/integrations/cloudflare
|
|
4
4
|
[33m@astrojs/cloudflare:build: [0m> astro-scripts build "src/**/*.ts" && tsc
|
|
5
5
|
[33m@astrojs/cloudflare:build: [0m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,60 @@
|
|
|
1
1
|
# @astrojs/cloudflare
|
|
2
2
|
|
|
3
|
+
## 2.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#4876](https://github.com/withastro/astro/pull/4876) [`d3091f89e`](https://github.com/withastro/astro/commit/d3091f89e92fcfe1ad48daca74055d54b1c853a3) Thanks [@matthewp](https://github.com/matthewp)! - Adds the Astro.cookies API
|
|
8
|
+
|
|
9
|
+
`Astro.cookies` is a new API for manipulating cookies in Astro components and API routes.
|
|
10
|
+
|
|
11
|
+
In Astro components, the new `Astro.cookies` object is a map-like object that allows you to get, set, delete, and check for a cookie's existence (`has`):
|
|
12
|
+
|
|
13
|
+
```astro
|
|
14
|
+
---
|
|
15
|
+
type Prefs = {
|
|
16
|
+
darkMode: boolean;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
Astro.cookies.set<Prefs>(
|
|
20
|
+
'prefs',
|
|
21
|
+
{ darkMode: true },
|
|
22
|
+
{
|
|
23
|
+
expires: '1 month',
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const prefs = Astro.cookies.get<Prefs>('prefs').json();
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
<body data-theme={prefs.darkMode ? 'dark' : 'light'}></body>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Once you've set a cookie with Astro.cookies it will automatically be included in the outgoing response.
|
|
34
|
+
|
|
35
|
+
This API is also available with the same functionality in API routes:
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
export function post({ cookies }) {
|
|
39
|
+
cookies.set('loggedIn', false);
|
|
40
|
+
|
|
41
|
+
return new Response(null, {
|
|
42
|
+
status: 302,
|
|
43
|
+
headers: {
|
|
44
|
+
Location: '/login',
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
See [the RFC](https://github.com/withastro/rfcs/blob/main/proposals/0025-cookie-management.md) to learn more.
|
|
51
|
+
|
|
52
|
+
## 2.0.0
|
|
53
|
+
|
|
54
|
+
### Major Changes
|
|
55
|
+
|
|
56
|
+
- [#4815](https://github.com/withastro/astro/pull/4815) [`ce0b92ba7`](https://github.com/withastro/astro/commit/ce0b92ba73072c0f0143829a53f870155ad4c7ff) Thanks [@AirBorne04](https://github.com/AirBorne04)! - adjusted esbuild config to work with worker environment (fixing solid js ssr)
|
|
57
|
+
|
|
3
58
|
## 1.0.2
|
|
4
59
|
|
|
5
60
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -2,9 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
An SSR adapter for use with Cloudflare Pages Functions targets. Write your code in Astro/Javascript and deploy to Cloudflare Pages.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Install
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Add the Cloudflare adapter to enable SSR in your Astro project with the following `astro add` command. This will install the adapter and make the appropriate changes to your `astro.config.mjs` file in one step.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
# Using NPM
|
|
11
|
+
npx astro add cloudflare
|
|
12
|
+
# Using Yarn
|
|
13
|
+
yarn astro add cloudflare
|
|
14
|
+
# Using PNPM
|
|
15
|
+
pnpm astro add cloudflare
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
If you prefer to install the adapter manually instead, complete the following two steps:
|
|
19
|
+
|
|
20
|
+
1. Add the Cloudflare adapter to your project's dependencies using your preferred package manager. If you’re using npm or aren’t sure, run this in the terminal:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @astrojs/cloudflare
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
2. Add the following to your `astro.config.mjs` file:
|
|
27
|
+
|
|
28
|
+
```js title="astro.config.mjs" ins={2, 5-6}
|
|
8
29
|
import { defineConfig } from 'astro/config';
|
|
9
30
|
import cloudflare from '@astrojs/cloudflare';
|
|
10
31
|
|
|
@@ -69,3 +90,15 @@ export default {
|
|
|
69
90
|
},
|
|
70
91
|
}
|
|
71
92
|
```
|
|
93
|
+
|
|
94
|
+
## Troubleshooting
|
|
95
|
+
|
|
96
|
+
For help, check out the `#support` channel on [Discord](https://astro.build/chat). Our friendly Support Squad members are here to help!
|
|
97
|
+
|
|
98
|
+
You can also check our [Astro Integration Documentation][astro-integration] for more on integrations.
|
|
99
|
+
|
|
100
|
+
## Contributing
|
|
101
|
+
|
|
102
|
+
This package is maintained by Astro's Core team. You're welcome to submit an issue or PR!
|
|
103
|
+
|
|
104
|
+
[astro-integration]: https://docs.astro.build/en/guides/integrations-guide/
|
package/dist/index.js
CHANGED
|
@@ -52,8 +52,8 @@ function createIntegration(args) {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
vite.ssr = {
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
...vite.ssr,
|
|
56
|
+
target: "webworker"
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
59
|
},
|
|
@@ -62,7 +62,9 @@ function createIntegration(args) {
|
|
|
62
62
|
const pkg = fileURLToPath(entryUrl);
|
|
63
63
|
await esbuild.build({
|
|
64
64
|
target: "es2020",
|
|
65
|
-
platform: "
|
|
65
|
+
platform: "neutral",
|
|
66
|
+
mainFields: ["main", "module"],
|
|
67
|
+
conditions: ["worker", "node"],
|
|
66
68
|
entryPoints: [pkg],
|
|
67
69
|
outfile: pkg,
|
|
68
70
|
allowOverwrite: true,
|
package/dist/server.advanced.js
CHANGED
|
@@ -15,7 +15,13 @@ function createExports(manifest) {
|
|
|
15
15
|
Symbol.for("astro.clientAddress"),
|
|
16
16
|
request.headers.get("cf-connecting-ip")
|
|
17
17
|
);
|
|
18
|
-
|
|
18
|
+
let response = await app.render(request, routeData);
|
|
19
|
+
if (app.setCookieHeaders) {
|
|
20
|
+
for (const setCookieHeader of app.setCookieHeaders(response)) {
|
|
21
|
+
response.headers.append("Set-Cookie", setCookieHeader);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return response;
|
|
19
25
|
}
|
|
20
26
|
return new Response(null, {
|
|
21
27
|
status: 404,
|
package/dist/server.directory.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
|
-
|
|
21
|
+
let response = await app.render(request, routeData);
|
|
22
|
+
if (app.setCookieHeaders) {
|
|
23
|
+
for (const setCookieHeader of app.setCookieHeaders(response)) {
|
|
24
|
+
response.headers.append("Set-Cookie", setCookieHeader);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return response;
|
|
22
28
|
}
|
|
23
29
|
return new Response(null, {
|
|
24
30
|
status: 404,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/cloudflare",
|
|
3
3
|
"description": "Deploy your site to cloudflare pages functions",
|
|
4
|
-
"version": "1.0
|
|
4
|
+
"version": "2.1.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"author": "withastro",
|
|
@@ -27,8 +27,11 @@
|
|
|
27
27
|
"esbuild": "^0.14.42"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"astro": "1.
|
|
31
|
-
"astro-scripts": "0.0.
|
|
30
|
+
"astro": "1.4.0",
|
|
31
|
+
"astro-scripts": "0.0.8",
|
|
32
|
+
"chai": "^4.3.6",
|
|
33
|
+
"cheerio": "^1.0.0-rc.11",
|
|
34
|
+
"mocha": "^9.2.2",
|
|
32
35
|
"wrangler": "^2.0.23"
|
|
33
36
|
},
|
|
34
37
|
"scripts": {
|
package/src/index.ts
CHANGED
|
@@ -67,8 +67,8 @@ export default function createIntegration(args?: Options): AstroIntegration {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
vite.ssr = {
|
|
70
|
+
...vite.ssr,
|
|
70
71
|
target: 'webworker',
|
|
71
|
-
noExternal: true,
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
74
|
},
|
|
@@ -77,7 +77,9 @@ export default function createIntegration(args?: Options): AstroIntegration {
|
|
|
77
77
|
const pkg = fileURLToPath(entryUrl);
|
|
78
78
|
await esbuild.build({
|
|
79
79
|
target: 'es2020',
|
|
80
|
-
platform: '
|
|
80
|
+
platform: 'neutral',
|
|
81
|
+
mainFields: ['main', 'module'],
|
|
82
|
+
conditions: ['worker', 'node'],
|
|
81
83
|
entryPoints: [pkg],
|
|
82
84
|
outfile: pkg,
|
|
83
85
|
allowOverwrite: true,
|
package/src/server.advanced.ts
CHANGED
|
@@ -26,7 +26,15 @@ export function createExports(manifest: SSRManifest) {
|
|
|
26
26
|
Symbol.for('astro.clientAddress'),
|
|
27
27
|
request.headers.get('cf-connecting-ip')
|
|
28
28
|
);
|
|
29
|
-
|
|
29
|
+
let response = await app.render(request, routeData);
|
|
30
|
+
|
|
31
|
+
if (app.setCookieHeaders) {
|
|
32
|
+
for (const setCookieHeader of app.setCookieHeaders(response)) {
|
|
33
|
+
response.headers.append('Set-Cookie', setCookieHeader);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return response;
|
|
30
38
|
}
|
|
31
39
|
|
|
32
40
|
return new Response(null, {
|
package/src/server.directory.ts
CHANGED
|
@@ -28,7 +28,15 @@ export function createExports(manifest: SSRManifest) {
|
|
|
28
28
|
Symbol.for('astro.clientAddress'),
|
|
29
29
|
request.headers.get('cf-connecting-ip')
|
|
30
30
|
);
|
|
31
|
-
|
|
31
|
+
let response = await app.render(request, routeData);
|
|
32
|
+
|
|
33
|
+
if (app.setCookieHeaders) {
|
|
34
|
+
for (const setCookieHeader of app.setCookieHeaders(response)) {
|
|
35
|
+
response.headers.append('Set-Cookie', setCookieHeader);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return response;
|
|
32
40
|
}
|
|
33
41
|
|
|
34
42
|
return new Response(null, {
|