You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/en/reference/api-reference.mdx
+11-7Lines changed: 11 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2495,15 +2495,15 @@ Actions help you build a type-safe backend you can call from client code and HTM
2495
2495
<Sincev="4.15.0" />
2496
2496
</p>
2497
2497
2498
-
The `defineAction()` utility is used to define new actions from the `src/actions/index.ts` file. This accepts a `handler()` function containing the server logic to run, and an optional `input` property to validate input parameters at runtime.
2498
+
The `defineAction()` utility is used to define new actions from the `src/actions/index.ts` file. This accepts a [`handler()`](#handler-property) function containing the server logic to run, and an optional [`input`](#input-validator) property to validate input parameters at runtime.
2499
2499
2500
2500
```ts
2501
2501
exportconst server = {
2502
-
getGreeting: defineAction({
2502
+
getGreeting: defineAction({
2503
2503
input: z.object({
2504
2504
name: z.string(),
2505
2505
}),
2506
-
handler: async (input) => {
2506
+
handler: async (input, context) => {
2507
2507
return`Hello, ${input.name}!`
2508
2508
}
2509
2509
})
@@ -2513,17 +2513,21 @@ export const server = {
2513
2513
#### `handler()` property
2514
2514
2515
2515
<p>
2516
-
<Sincev="4.15.0" />
2516
+
2517
+
**Type:**`(input, context) => any`
2517
2518
</p>
2518
2519
2519
-
`defineAction()` accepts a `handler()` function containing the server logic to run when the action is called. This function can return data that is automatically serialized and sent to the caller.
2520
+
`defineAction()` requires a `handler()` function containing the server logic to run when the action is called. Data returned from the handler is automatically serialized and sent to the caller.
2521
+
2522
+
The `handler()` is called with user input as its first argument. If an [`input`](#input-validator) validator is set, the user input will be validated before being passed to the handler. The second argument is a `context` object containing most of Astro’s [standard endpoint context](#endpoint-context), excluding `getActionResult()`, `callAction()`, and `redirect()`.
2520
2523
2521
-
Return values are parsed using the [devalue library](https://github.com/Rich-Harris/devalue). This supports JSON values, along with instances of `Date()`, `Map()`, `Set()`, or`URL()`.
2524
+
Return values are parsed using the [devalue library](https://github.com/Rich-Harris/devalue). This supports JSON values and instances of `Date()`, `Map()`, `Set()`, and`URL()`.
2522
2525
2523
2526
#### `input` validator
2524
2527
2525
2528
<p>
2526
-
<Sincev="4.15.0" />
2529
+
2530
+
**Type:**`ZodObject | undefined`
2527
2531
</p>
2528
2532
2529
2533
The optional `input` property accepts a Zod validator to validate handler inputs at runtime. If the action fails to validate, [a `BAD_REQUEST` error](#actionerror) is returned and the `handler` is not called.
Copy file name to clipboardExpand all lines: src/content/docs/en/reference/configuration-reference.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1204,7 +1204,7 @@ By default, Astro's i18n routing creates pages that redirect your visitors to a
1204
1204
1205
1205
When `i18n.routing.fallback: "rewrite"` is configured, Astro will create pages that render the contents of the fallback page on the original, requested URL.
1206
1206
1207
-
With the following configuration, if you have the file `src/pages/en/about.astro` but not `src/pages/fr/about.astro`, the `astro build` command will generate `dist/fr/about.html` with the same content as the `dist/en/index.html` page.
1207
+
With the following configuration, if you have the file `src/pages/en/about.astro` but not `src/pages/fr/about.astro`, the `astro build` command will generate `dist/fr/about.html` with the same content as the `dist/en/about.html` page.
1208
1208
Your site visitor will see the English version of the page at `https://example.com/fr/about/` and will not be redirected.
0 commit comments