Bindings
Once you have set up next-on-pages, you can access bindings from any route of your Next.js app via getRequestContext
:
Add bindings to your Pages project by adding them to your wrangler.toml
configuration file.
To ensure that the env
object from getRequestContext().env
above has accurate TypeScript types, install @cloudflare/workers-types
↗ and create a TypeScript declaration file ↗.
Install Workers Types:
Add Workers Types to your tsconfig.json
file, replacing the date below with your project’s compatibility date:
Create an env.d.ts
file in the root directory of your Next.js app, and explicitly declare the type of each binding:
Access context about the incoming request from the cf
object, as well as lifecycle methods from the ctx
object from the return value of getRequestContext()
↗: