@astrojs/cloudflare
Advanced tools
Comparing version 2.0.0 to 2.1.0
# @astrojs/cloudflare | ||
## 2.1.0 | ||
### Minor Changes | ||
- [#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 | ||
`Astro.cookies` is a new API for manipulating cookies in Astro components and API routes. | ||
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`): | ||
```astro | ||
--- | ||
type Prefs = { | ||
darkMode: boolean; | ||
}; | ||
Astro.cookies.set<Prefs>( | ||
'prefs', | ||
{ darkMode: true }, | ||
{ | ||
expires: '1 month', | ||
} | ||
); | ||
const prefs = Astro.cookies.get<Prefs>('prefs').json(); | ||
--- | ||
<body data-theme={prefs.darkMode ? 'dark' : 'light'}></body> | ||
``` | ||
Once you've set a cookie with Astro.cookies it will automatically be included in the outgoing response. | ||
This API is also available with the same functionality in API routes: | ||
```js | ||
export function post({ cookies }) { | ||
cookies.set('loggedIn', false); | ||
return new Response(null, { | ||
status: 302, | ||
headers: { | ||
Location: '/login', | ||
}, | ||
}); | ||
} | ||
``` | ||
See [the RFC](https://github.com/withastro/rfcs/blob/main/proposals/0025-cookie-management.md) to learn more. | ||
## 2.0.0 | ||
@@ -4,0 +53,0 @@ |
@@ -18,3 +18,9 @@ import "./shim.js"; | ||
); | ||
return app.render(request, routeData); | ||
let response = await app.render(request, routeData); | ||
if (app.setCookieHeaders) { | ||
for (const setCookieHeader of app.setCookieHeaders(response)) { | ||
response.headers.append("Set-Cookie", setCookieHeader); | ||
} | ||
} | ||
return response; | ||
} | ||
@@ -21,0 +27,0 @@ return new Response(null, { |
@@ -21,3 +21,9 @@ import "./shim.js"; | ||
); | ||
return app.render(request, routeData); | ||
let response = await app.render(request, routeData); | ||
if (app.setCookieHeaders) { | ||
for (const setCookieHeader of app.setCookieHeaders(response)) { | ||
response.headers.append("Set-Cookie", setCookieHeader); | ||
} | ||
} | ||
return response; | ||
} | ||
@@ -24,0 +30,0 @@ return new Response(null, { |
{ | ||
"name": "@astrojs/cloudflare", | ||
"description": "Deploy your site to cloudflare pages functions", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"type": "module", | ||
@@ -30,4 +30,7 @@ "types": "./dist/index.d.ts", | ||
"devDependencies": { | ||
"astro": "1.2.8", | ||
"astro-scripts": "0.0.7", | ||
"astro": "1.4.0", | ||
"astro-scripts": "0.0.8", | ||
"chai": "^4.3.6", | ||
"cheerio": "^1.0.0-rc.11", | ||
"mocha": "^9.2.2", | ||
"wrangler": "^2.0.23" | ||
@@ -34,0 +37,0 @@ }, |
@@ -9,4 +9,9 @@ # @astrojs/cloudflare | ||
```bash | ||
```sh | ||
# Using NPM | ||
npx astro add cloudflare | ||
# Using Yarn | ||
yarn astro add cloudflare | ||
# Using PNPM | ||
pnpm astro add cloudflare | ||
``` | ||
@@ -89,1 +94,13 @@ | ||
``` | ||
## Troubleshooting | ||
For help, check out the `#support` channel on [Discord](https://astro.build/chat). Our friendly Support Squad members are here to help! | ||
You can also check our [Astro Integration Documentation][astro-integration] for more on integrations. | ||
## Contributing | ||
This package is maintained by Astro's Core team. You're welcome to submit an issue or PR! | ||
[astro-integration]: https://docs.astro.build/en/guides/integrations-guide/ |
@@ -29,3 +29,11 @@ import './shim.js'; | ||
); | ||
return app.render(request, routeData); | ||
let response = await app.render(request, routeData); | ||
if (app.setCookieHeaders) { | ||
for (const setCookieHeader of app.setCookieHeaders(response)) { | ||
response.headers.append('Set-Cookie', setCookieHeader); | ||
} | ||
} | ||
return response; | ||
} | ||
@@ -32,0 +40,0 @@ |
@@ -31,3 +31,11 @@ import './shim.js'; | ||
); | ||
return app.render(request, routeData); | ||
let response = await app.render(request, routeData); | ||
if (app.setCookieHeaders) { | ||
for (const setCookieHeader of app.setCookieHeaders(response)) { | ||
response.headers.append('Set-Cookie', setCookieHeader); | ||
} | ||
} | ||
return response; | ||
} | ||
@@ -34,0 +42,0 @@ |
Sorry, the diff of this file is not supported yet
32929
492
105
6