Hugo support in Cloudflare Workers

I was able to make it work by doing this in the wrangler config (see last line):

# Configure Cloudflare Worker

name = 'hosting-cloudflare-worker'
compatibility_date = "2025-05-26"

[build]
command = "./build.sh"

[assets]
directory = "./public"
not_found_handling = "404-page"

Then publish one or more 404.html files in the same way that you did for CF Pages.

You can define a custom page to be displayed when Pages cannot find a requested file by creating a 404.html file. Pages will then attempt to find the closest 404 page. If one is not found in the same directory as the route you are currently requesting, it will continue to look up the directory tree for a matching 404.html file, ending in /404.html . This means that you can define custom 404 paths for situations like /blog/404.html and /404.html , and Pages will automatically render the correct one depending on the situation.

https://developers.cloudflare.com/pages/configuration/serving-pages/#not-found-behavior

2 Likes

That’s all I needed to add. Thanks

FYI

I’ve added a custom 404 error page to the example site referenced above. See repository:
https://github.com/jmooring/hosting-cloudflare-worker

The new template system (symmetrical content and layout paths) makes this setup much easier to understand, and the improved organization is great.

This link is broken and will redirect to the custom 404 error page:
https://hosting-cloudflare-worker.joe-mooring.workers.dev/foo

1 Like

Mine is also configured the same way for easier translation. That’s why I only needed to add not_found_handling = "404-page".

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.