Run your Cloudflare Pages Functions locally when running `gatsby develop`.
npm install gatsby-plugin-cloudflare-functionsRun your Cloudflare Pages Functions locally when running gatsby develop.
``shell`
npm install gatsby-plugin-cloudflare-functions
Add the plugin to your gatsby-config.js.
`javascript`
module.exports = {
plugins: ['gatsby-plugin-cloudflare-functions'],
}
The plugin uses wrangler to run your functions which
automatically pick configuration from a wrangler.toml or wrangler.json file and.dev.vars
variables/secrets from a file. .wrangler/
It is recommended to add to your .gitignore file to avoid committing the temporary
files that wrangler creates.
if you don't use a wrangler.toml file to configure Cloudflare Pages you can also configure thewrangler.toml
plugin via plugin options. Bindings defined here take precedence over those in a
file.
See the example below which includes all available plugin options.
`javascript`
module.exports = {
plugins: [
{
resolve: 'gatsby-plugin-cloudflare-functions',
options: {
compatibilityDate: '2024-11-15',
compatibilityFlag: ['nodejs_als'],
binding: {
MY_VAR: process.env.MY_VAR,
MY_SECRET: process.env.MY_SECRET,
},
kv: ['MY_KV_NAMESPACE'],
r2: ['MY_R2_BUCKET'],
d1: ['MY_D1_DATABASE'],
do: ['MY_DURABLE_OBJECT'],
ai: 'MY_AI',
},
},
],
}
Runtime compatibility date to apply.
See
Runtime compatibility flags to apply.
See
Bind environment variables or secrets.
Alternatively these can be specified in a file called .dev.vars` in dotenv format.
Binding name of KV namespace to bind.
Binding name of R2 bucket to bind.
Binding name of D1 database to bind.
Binding name of Durable Object to bind.
Binding name of Workers AI to bind.