Edge function path glob

Hi,

I currently have the following in my netlify.toml

[[edge_functions]]
function = “regionalise-courses”
path = “/courses/register-for-a-training-course/*”

I would expect this to only apply to pages one level beneath ‘register-for-a-training-course’ so ‘/courses/register-for-a-training-course/course-1’ and ‘/courses/register-for-a-training-course/course-2’ but it’s also applying to the following URLs ‘/courses/register-for-a-training-course/course-1/book’ and ‘/courses/register-for-a-training-course/course-2/book’.

Have I done something wrong here?

Cheers
Mark

No.

Using a * (wildcard) will match anything below the path, regardless of level.

Thanks @jasiqli.

How can I match to just one level below?

I don’t believe there is a way to do that.

I don’t think that is true, see here - Glob Tool | DigitalOcean

So you’ve tried one of these options and succeeded in matching only the single level — not recursing down through all levels?

The link above shows that a single * just matches one level whereas ** will match multiple but Netlify edge function path isn’t behaving like this

Hence my belief there is no way to do so (on Netlify.)

Netlify’s wildcards are not glob patterns, /* means everything after that path, regardless of the level.

Inside your Edge Function, you’d have to check the condition yourself and terminate its execution. If you want to completely prevent the Edge Function from running for the nested paths, you can use the advanced configuration and generate your own RegEx pattern: Create an Edge Functions integration | Netlify Docs

Side note: I’ll also be closing your helpdesk ticket in favour of this thread.

1 Like

Ok thanks @hrishikesh, I will check the path within the function and return it if it doesn’t match instead.

1 Like

Just coming back to this as your docs state the paths are “glob-style” so does that still stand?

Also the docs state “path: glob-style path on which to run the edge function. Must start with /, for example path = "/*". Accepts a single string or an array of strings.

I have tried to add an array of strings but I’m getting the following error in the terminal:

Configuration property edge_functions[2].path must be a string.

Invalid syntax

  [[edge_functions]]
  path = [
    "/courses/register-for-a-training-course",
    "/*/courses/register-for-a-training-course"
  ]

Valid syntax

  [[edge_functions]]
  path = "/hello"
  function = "hello"

Regards
Mark

Hi @reasonmark,

The docs were incorrect. The path must only be a string.

Regarding glob-style, that’s also being discussed here: Please clarify documentation for edge functions excludedPath - Support / Edge Functions - Netlify Support Forums