cloudflare-docs
cloudflare-docs copied to clipboard
A function at `/foo/[path].js` will match requests for `/foo/index.html`, but not `/foo/`.
I updated the title and description to give a clearer explanation of what I found confusing.
Expected Behavior
I made an example project with some wildcard routes. It's deployed to cloudflare-pages-routing.pages.dev.
The functions routing docs explain how to use [[path]].js and [path].js for wildcard matching. When I read them, I think of the route matching in my sample project as:
/foo/*/bar/**
There isn't an explanation for matching empty routes (ex: /foo/ or /bar/) and I was expecting those to be the equivalent of the corresponding default resource (ex: /foo/index.html, /bar/index.html). However, the behavior differs depending on whether or not you explicitly include index.html in a request.
I was expecting a request to /foo/ or /foo/index.html to both match the route at functions/[path].js, but it only works for /foo/index.html.
The behavior for functions/bar/[[path]].js works like I was expecting. A request to /bar/ or /bar/index.html will match the functions/bar/[[path]].js route.
Actual Behavior
- A request to
/foo/does not match thefunctions/foo/[path].jsroute. - A request to
/foo/index.htmldoes match thefunctions/foo/[path].jsroute.
Given the routes functions/foo/[path].js and functions/bar/[[path]].js and static HTML at public/foo/index.html and public/bar/index.html, you'll get the following results from requests:
| URL | Response |
|---|---|
| https://cloudflare-pages-routing.pages.dev/foo/ | /foo/index.html |
| https://cloudflare-pages-routing.pages.dev/foo/index.html | /foo/[pages].js |
| https://cloudflare-pages-routing.pages.dev/bar/ | /bar/[[path]].js |
| https://cloudflare-pages-routing.pages.dev/bar/index.html | /bar/[[path]].js |
The request to /foo seems like the odd one out.
Section that requires update
The functions routing docs.
Additional information
The local behavior of wrangler matches the current pages.dev behavior.
@lauragift21 can you work with @deadlypants1973 on this one?
Change required to resolve this issue has been merged, so closing for now.