@astrojs/cloudflare 2.0.0 → 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.
@@ -1,5 +1,5 @@
1
- @astrojs/cloudflare:build: cache hit, replaying output 77d2b45b1cd7ea2d
2
- @astrojs/cloudflare:build: 
3
- @astrojs/cloudflare:build: > @astrojs/cloudflare@2.0.0 build /home/runner/work/astro/astro/packages/integrations/cloudflare
4
- @astrojs/cloudflare:build: > astro-scripts build "src/**/*.ts" && tsc
5
- @astrojs/cloudflare:build: 
1
+ @astrojs/cloudflare:build: cache hit, replaying output f779b2bf8afec1e9
2
+ @astrojs/cloudflare:build: 
3
+ @astrojs/cloudflare:build: > @astrojs/cloudflare@2.1.0 build /home/runner/work/astro/astro/packages/integrations/cloudflare
4
+ @astrojs/cloudflare:build: > astro-scripts build "src/**/*.ts" && tsc
5
+ @astrojs/cloudflare:build: 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,54 @@
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
+
3
52
  ## 2.0.0
4
53
 
5
54
  ### Major Changes
package/README.md CHANGED
@@ -6,8 +6,13 @@ An SSR adapter for use with Cloudflare Pages Functions targets. Write your code
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
8
 
9
- ```bash
9
+ ```sh
10
+ # Using NPM
10
11
  npx astro add cloudflare
12
+ # Using Yarn
13
+ yarn astro add cloudflare
14
+ # Using PNPM
15
+ pnpm astro add cloudflare
11
16
  ```
12
17
 
13
18
  If you prefer to install the adapter manually instead, complete the following two steps:
@@ -85,3 +90,15 @@ export default {
85
90
  },
86
91
  }
87
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/
@@ -15,7 +15,13 @@ function createExports(manifest) {
15
15
  Symbol.for("astro.clientAddress"),
16
16
  request.headers.get("cf-connecting-ip")
17
17
  );
18
- return app.render(request, routeData);
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,
@@ -18,7 +18,13 @@ function createExports(manifest) {
18
18
  Symbol.for("astro.clientAddress"),
19
19
  request.headers.get("cf-connecting-ip")
20
20
  );
21
- return app.render(request, routeData);
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": "2.0.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.2.8",
31
- "astro-scripts": "0.0.7",
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": {
@@ -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
- return app.render(request, routeData);
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, {
@@ -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
- return app.render(request, routeData);
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, {