Cloudflare Service bindings with nuxt
I'm working on an SSR Nuxt app that is going to be deployed to cloudflare and I'm having a great deal of trouble accessing the cloudflare bindings (specifically the service bindings).
I have a nitro plugin where I'm trying to access my service binding:
export default defineNitroPlugin((nitroApp) => {
nitroApp.hooks.hook('render:html', async (html, { event }) => {
console.log(event);
const $fetch = get(event, 'context.cloudflare.env.Self');
if (!isUndefined($fetch)) {
globalThis.$fetch = $fetch;
}
});
});
For whatever reason cloudflare is not defined. When I look at this article: https://developers.cloudflare.com/pages/framework-guides/deploy-a-nuxt-site/ it infers that you can only access the bindings in middleware or server routes.
Is it possible to access the bindings in nuxt pages, plugins or nitro plugins? I'm having trouble understanding how it would be useful for me unless I can have access to the bindings in those contexts.
Deploy a Nuxt site · Cloudflare Pages docs
Nuxt is a web framework making web Vue.js-based development simple and powerful.
0 Replies