The brief

To serve a Worker's static assets from a URL path prefix, such as example.com/blog/, users can set assets.base_path in their Wrangler configuration file or worker.assets.basePath in cloudflare.config.ts. This allows assets to be served from the specified path without requiring files to be nested in a matching directory. For instance, setting assets.base_path to /blog in the Wrangler configuration file enables serving built assets from /blog/.

The configuration for serving assets from /blog/ involves setting the basePath to /blog in the worker.assets or assets object, depending on whether Cloudflare CLI or Wrangler is used. Requests to /blog/ will serve the corresponding files from the asset directory, such as dist/index.html for requests to /blog/ and dist/posts/post1.html for requests to /blog/posts/post1. Paths in headers, redirects, and runworkerfirst use the full public path, including /blog.