Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/content/docs/pages/framework-guides/nextjs/ssr/bindings.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,29 @@ export async function GET(request) {
// ...
}
```

## Import with npm create cloudflare

If you initialized your project using the command:

```bash
npm create cloudflare@latest -- my-next-app --framework=next --platform=pages
```

the recommended way to access bindings is through getCloudflareContext from the [@opennextjs/cloudflare](https://opennext.js.org/cloudflare/bindings) package:

```js
import { getCloudflareContext } from "@opennextjs/cloudflare";

export async function GET(request) {
const myKv = getCloudflareContext().env.MY_KV_NAMESPACE;
await myKv.put("foo", "bar");
const foo = await myKv.get("foo");

return new Response(foo);
}

```
Remember, with this approach you do not need to install ```@cloudflare/next-on-pages```,
nor do you need to add ```jssetupDevPlatform();``` to the ```next.config.mjs```
file.