Skip to content

Commit ad8586e

Browse files
committed
Fail open/closed docs
1 parent 14241cd commit ad8586e

File tree

1 file changed

+43
-26
lines changed

1 file changed

+43
-26
lines changed

src/content/docs/pages/functions/routing.mdx

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@ import { FileTree } from "~/components";
1010
Functions utilize file-based routing. Your `/functions` directory structure determines the designated routes that your Functions will run on. You can create a `/functions` directory with as many levels as needed for your project's use case. Review the following directory:
1111

1212
<FileTree>
13+
1314
- ...
1415
- functions
15-
- index.js
16-
- helloworld.js
17-
- howdyworld.js
18-
- fruits
19-
- index.js
20-
- apple.js
21-
- banana.js
16+
- index.js
17+
- helloworld.js
18+
- howdyworld.js
19+
- fruits
20+
- index.js
21+
- apple.js
22+
- banana.js
23+
2224
</FileTree>
2325

2426
The following routes will be generated based on the above file structure. These routes map the URL pattern to the `/functions` file that will be invoked when a visitor goes to the URL:
@@ -80,13 +82,15 @@ More specific routes (routes with fewer wildcards) take precedence over less spe
8082
Review the following `/functions/` directory structure:
8183

8284
<FileTree>
85+
8386
- ...
8487
- functions
85-
- date.js
86-
- users
87-
- special.js
88-
- [user].js
89-
- [[catchall]].js
88+
- date.js
89+
- users
90+
- special.js
91+
- [user].js
92+
- [[catchall]].js
93+
9094
</FileTree>
9195

9296
The following requests will match the following files:
@@ -106,7 +110,7 @@ For files which match a single URL segment (use a single set of brackets), the v
106110

107111
```js
108112
export function onRequest(context) {
109-
return new Response(context.params.user)
113+
return new Response(context.params.user);
110114
}
111115
```
112116

@@ -116,7 +120,7 @@ For files which match against multiple URL segments (use a double set of bracket
116120

117121
```js
118122
export function onRequest(context) {
119-
return new Response(JSON.stringify(context.params.catchall))
123+
return new Response(JSON.stringify(context.params.catchall));
120124
}
121125
```
122126

@@ -138,9 +142,9 @@ Create a `_routes.json` file to control when your Function is invoked. It should
138142

139143
This file will include three different properties:
140144

141-
* **version**: Defines the version of the schema. Currently there is only one version of the schema (version 1), however, we may add more in the future and aim to be backwards compatible.
142-
* **include**: Defines routes that will be invoked by Functions. Accepts wildcard behavior.
143-
* **exclude**: Defines routes that will not be invoked by Functions. Accepts wildcard behavior. `exclude` always take priority over `include`.
145+
- **version**: Defines the version of the schema. Currently there is only one version of the schema (version 1), however, we may add more in the future and aim to be backwards compatible.
146+
- **include**: Defines routes that will be invoked by Functions. Accepts wildcard behavior.
147+
- **exclude**: Defines routes that will not be invoked by Functions. Accepts wildcard behavior. `exclude` always take priority over `include`.
144148

145149
:::note
146150

@@ -154,9 +158,9 @@ Below is an example of a `_routes.json`.
154158

155159
```json
156160
{
157-
"version": 1,
158-
"include": ["/*"],
159-
"exclude": []
161+
"version": 1,
162+
"include": ["/*"],
163+
"exclude": []
160164
}
161165
```
162166

@@ -166,16 +170,29 @@ Below is another example of a `_routes.json` file. Any route inside the `/build`
166170

167171
```json
168172
{
169-
"version": 1,
170-
"include": ["/*"],
171-
"exclude": ["/build/*"]
173+
"version": 1,
174+
"include": ["/*"],
175+
"exclude": ["/build/*"]
172176
}
173177
```
174178

179+
## Fail open / closed
180+
181+
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.
182+
183+
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com) and select your account.
184+
2. In **Account Home**, select **Workers & Pages**.
185+
3. In **Overview**, select your Pages project.
186+
4. Select **Settings** > **Runtime** > **Fail open / closed**.
187+
188+
"Fail open" means that static assets will continue to be served, even if Pages Functions would ordinarily have run first. "Fail closed" means an error page will be returned, rather than static assets.
189+
190+
The daily request limit can be removed entirely by upgrading to [Workers Standard](/workers/platform/pricing/#workers).
191+
175192
### Limits
176193

177194
Functions invocation routes have the following limits:
178195

179-
* You must have at least one include rule.
180-
* You may have no more than 100 include/exclude rules combined.
181-
* Each rule may have no more than 100 characters.
196+
- You must have at least one include rule.
197+
- You may have no more than 100 include/exclude rules combined.
198+
- Each rule may have no more than 100 characters.

0 commit comments

Comments
 (0)