cloudflare-docs icon indicating copy to clipboard operation
cloudflare-docs copied to clipboard

A function at `/foo/[path].js` will match requests for `/foo/index.html`, but not `/foo/`.

Open ryanjaeb opened this issue 3 years ago • 1 comments

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:

  1. /foo/*
  2. /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 the functions/foo/[path].js route.
  • A request to /foo/index.html does match the functions/foo/[path].js route.

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.

ryanjaeb avatar Nov 25 '21 14:11 ryanjaeb

@lauragift21 can you work with @deadlypants1973 on this one?

jkup avatar Jul 06 '22 15:07 jkup

Change required to resolve this issue has been merged, so closing for now.

haleycode avatar Oct 05 '22 20:10 haleycode