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?2 Replies
with
npx wrangler pages deployment tail
, i see static assets fly out, and the get requests for pages that are serverside rendered, but none of the logging, etc from functions/_middleware.js.
the functions folder is the root of our project (not the output folder), as instructed by the docs.
we have a rails backend, and have almost nothing in our server/ folder in the nuxt app. Some nuxt middleware, a few very rarely used routes, and an error plugin. But nearly all of our vue pages are built such that they should be rendered by the server when directly navigated to.👋 hey @Ben Akroyd did you ever get this solved??
I'm running into something very similar