#Can workers alter requests made to Cloudflare pages?

20 messages · Page 1 of 1 (latest)

vapid fox
finite vessel
#

Putting a Worker in front of Pages is a bit buggy and not recommended - as a first step can you try retrying the most recent deployment on the Pages project?

Longterm we would recommend looking into Pages Functions for running Workers alongside Pages projects

vapid fox
#

Redeployment didn't fix the problem for me.

#

While building the application, directories static and functions are created automatically, but I don't see any way of placing _headers

#

I would need to either fork next-on-pages to implement support or I could use Direct Upload in which I can easily add a new file, but I need manually upload files on every deployment.

finite vessel
#

You would need to copy them into the output directory after the build is complete

#

I have no experience with next-on-pages however, it may be running a Function that causes _headers to not run

vapid fox
#

Yeah but next-on-pages is creating the output directory automatically after git push, so I can't just copy anything in there.

finite vessel
#

According to the repo above, the build command is npx @cloudflare/next-on-pages --experimental-minify and the output dir is .vercel/output/static

So you could theoretically change the build command to

npx @cloudflare/next-on-pages --experimental-minify && cp -v ./_headers ./.vecel/output/static/```
HOWEVER this probably wont actually work if next-on-pages is using Functions on every route, which I suspect it is
#

In which case you will likely have to modify next-on-pages to suit that need

#

Running a regular Worker on top of Pages is the kind of unsupported thing where I can't really help a whole lot, one workaround to it causing 522s in the past was retrying the most recent Pages deploy after publishing the Worker but if that doesn't work then there isn't a lot to be said

vapid fox
#

Copying _headers during build works well 🙂 Thank you very much

finite vessel
#

Ah nice! Glad to hear!

vapid fox
#

@finite vessel Could you please help me with one more thing? Headers generally work ok, but they are never applied to the index page. I have tried following paths:

#
  X-Test: 1

https://:project.pages.dev/
  X-Test: 2

https://:project.pages.dev/*
  X-Test: 3

https://:build.tklm.pages.dev
  X-Test: 4

https://::build.tklm.pages.dev/
  X-Test: 5

https://:build.tklm.pages.dev/*
  X-Test: 6

/
  X-Test: 7

*
  X-Test: 8

/*
  X-Test: 9

/index
  X-Test: 10```
#

Headers 3 & 9 are showing up on other resources, but nothing is applied to index.

finite vessel
#

As I alluded to earlier, they won't apply on pages that a Pages Function is running on, so likely that's the case?

vapid fox
#

Ah, I see. In such case, I will apply them to the page function directly. Thank you