Skip to content

Commit

Permalink
add bindings section in qwik pages guide
Browse files Browse the repository at this point in the history
  • Loading branch information
dario-piotrowicz committed Mar 13, 2023
1 parent 3d16109 commit eb51907
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions content/pages/framework-guides/deploy-a-qwik-site.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,29 @@ For the complete guide to deploying your first site to Cloudflare Pages, refer t
After deploying your site, you will receive a unique subdomain for your project on `*.pages.dev`.
Every time you commit new code to your Qwik site, Cloudflare Pages will automatically rebuild your project and deploy it. You will also get access to [preview deployments](/pages/platform/preview-deployments/) on new pull requests, to preview how changes look to your site before deploying them to production.

## Use bindings in your Qwik application

A [binding](/pages/platform/functions/bindings/) allows your application to interact with Cloudflare developer products, such as [KV](https://developers.cloudflare.com/workers/learning/how-kv-works/), [Durable Object](/workers/learning/using-durable-objects/), [R2](/r2/), and [D1](https://blog.cloudflare.com/introducing-d1/).

In QwikCity you can add server-side code via [routeLoaders](https://qwik.builder.io/qwikcity/route-loader/) and [actions](https://qwik.builder.io/qwikcity/action/). In such server side code you can then use access bindings set for your application by accessing them via the `platform` object provided by the framework.

The following code block shows an example of accessing a KV namespace in QwikCity.

```typescript
---
filename: src/routes/index.tsx
highlight: [4, 5]
---
// ...

export const useGetServerTime = routeLoader$(({ platform }) => {
// the type KVNamespace comes from the @cloudflare/workers-types package
const { MY_KV } = (platform as { MY_KV: KVNamespace }));

return {
// ....
}
});
```

{{<render file="_learn-more.md" withParameters="Qwik">}}

0 comments on commit eb51907

Please sign in to comment.