ENF News Bot
Automated News Bot
- Joined
- Apr 15, 2022
- Messages
- 2,591
You can now serve your Worker's static assets from a URL path prefix, such as
Previously, to serve assets from
Use Wrangler 4.148.0 ↗︎ or later. With
For example, this configuration serves your built assets from
The following content appears twice: first for the Cloudflare CLI (
Cloudflare CLI
cloudflare.config.tsts
Wrangler
Requests to
Paths in
For more information, refer to Serving a subdirectory.
Continue reading...
example.com/blog/, without changing your build output.Previously, to serve assets from
/blog/, you had to nest your files in a matching blog directory. Now, set assets.base_path in your Wrangler configuration file, or worker.assets.basePath in cloudflare.config.ts, and keep your files at the root of your asset directory.Use Wrangler 4.148.0 ↗︎ or later. With
cloudflare.config.ts, use cf 1.0.0-beta.13 ↗︎ or later.For example, this configuration serves your built assets from
/blog/:The following content appears twice: first for the Cloudflare CLI (
cf), then for Wrangler. Use cf for new projects. In an existing project, use the CLI that the project already uses.Cloudflare CLI
cloudflare.config.tsts
Code:
import { defineConfig } from "cf/config";
export default defineConfig({
worker: {
name: "blog",
// Set this to today's date
compatibilityDate: "2026-11-12",
assets: {
basePath: "/blog",
},
},
});
Wrangler
Code:
{
"$schema": "./node_modules/wrangler/config-schema.json",
"assets": {
"directory": "./dist",
"base_path": "/blog"
}
}
Code:
[assets]
directory = "./dist"
base_path = "/blog"
Requests to
/blog/ serve dist/index.html, and requests to /blog/posts/post1 serve dist/posts/post1.html. Requests outside /blog/ do not match your static assets and run your Worker, if it has one.Paths in
_headers, _redirects, and run_worker_first use the full public path, including /blog. If you build with the Cloudflare Vite plugin, also set Vite's base option to /blog/.For more information, refer to Serving a subdirectory.
Continue reading...