I would like to pass data from my Cloudflare Functions middleware to my Cloudflare Function. I suspect I can do this using context.data. However, the documentation in Cloudflare does not specify what this field is. Has anyone got any ideas what this field is and how it is supposed to be used?
I got an answer on Cloudflare:
"It’s an arbitrary object you can attach data to that will persist during the request. The most common use-cases are for middleware that handles auth and may need to set context.data.username or similar."
Ref: https://community.cloudflare.com/t/what-is-context-data-in-pages-functions/476559/2?u=safa
More Notes: To use context.data make sure that you do not replace it:
context.data = "some value";
Instead you should add a property like so:
context.data.myprop = "some value";
If you do not do this data will not be persisted.