Ben Akroyd
CDCloudflare Developers
•Created by Ben Akroyd on 2/14/2025 in #pages-help
Difficulty getting started with functions/_middleware.js
We have a nuxt app running on cloudflare pages. I'm trying to get some middleware running following the basic instructions fond tin the docs. For now, I'm just looking for confirmation that the middleware runs- can log something we can pickup in a wrangler log trail, add a header to a requst, anything. Evenutally, I'd want to use the middleware to connect us to some bug tracking solution.
However, I just CAN'T seem to get functions/_middleware.js to do anything. I've tried the example provided in the docs plus a few logging statements. I've written some custom code to add headers, then to raise errors, then modify the body of html responses- nothing works, and I have zero visibility into why, both locally with wrangler or on a production-like feature app.
Our nuxt config sets the nitro preset to 'cloudflare-pages', that handles all the cloudflare settings that would normally go into wrangler.toml for us- we have no wrangler.toml in the root of our project. Its my understanding though, that there is no additional config needed to run functions.
We use github actions for deployment to the feature app, and it invokes
npx wrangler pages deploy dist
with the proper project flag.
I've added the compatibility flag nodejs_compat to the pages worker in question via the admin, in the theory I was using some node based function without realising it and nitro couldn't handle- though I don't think I am, and its not making any difference.
nuxi info:
- Operating System: Darwin
- Node Version: v23.6.1
- Nuxt Version: 3.15.4
- CLI Version: 3.21.1
- Nitro Version: 2.10.4
- Package Manager: [email protected]
- Builder: -
ANY idea how to proceed here?5 replies