diff --git a/src/content/docs/pages/functions/routing.mdx b/src/content/docs/pages/functions/routing.mdx index cca5cb13bbf..91c401806c6 100644 --- a/src/content/docs/pages/functions/routing.mdx +++ b/src/content/docs/pages/functions/routing.mdx @@ -160,11 +160,11 @@ This file will include three different properties: :::note -Wildcards match any number of path segments (slashes). For example, `/users/*` will match everything after the`/users/` path. +Wildcards match any number of path segments (slashes). For example, `/users/*` will match everything after the `/users/` path. ::: -#### Example configuration +#### Example configurations Below is an example of a `_routes.json`. @@ -188,6 +188,20 @@ Below is another example of a `_routes.json` file. Any route inside the `/build` } ``` +A wildcard can also appear before a file extension, and it matches at any depth. This is useful when static files and Function routes share a path, such as an API that serves pre-rendered `.json` files alongside routes handled by a Function. + +With the following `_routes.json`, `/api/users/1.json` and `/api/users/1/posts.json` are served as static assets without invoking the Function. `/api/users/1` and `/api/search` still invoke it. + +```json +{ + "version": 1, + "include": ["/api/*"], + "exclude": ["/api/*.json"] +} +``` + +This rule excludes every `.json` path under `/api/`, including any `.json` response your Function generates dynamically. For example, a request to `/api/export.json` will not reach your Function, even if no matching static file exists. + ## Fail open / closed If on the Workers Free plan, you can configure how Pages behaves when your daily free tier allowance of Pages Functions requests is exhausted. If, for example, you are performing authentication checks or other critical functionality in your Pages Functions, you may wish to disable your Pages project when the allowance is exhausted.