-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Actions: Allow actions to be called on the server (#11088)
* wip: consume async local storage from `defineAction()` * fix: move async local storage to middleware. It works! * refactor: remove content-type check on JSON. Not needed * chore: remove test * feat: support server action calls * refactor: parse path keys within getAction * feat(test): server-side action call * chore: changeset * fix: reapply context on detected rewrite * feat(test): action from server with rewrite * chore: stray import change * feat(docs): add endpoints to changeset * chore: minor -> patch * fix: move rewrite check to start of middleware * fix: bad getApiContext() import --------- Co-authored-by: bholmesdev <bholmesdev@gmail.com>
- Loading branch information
1 parent
e71348e
commit 9566fa0
Showing
12 changed files
with
132 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
"astro": patch | ||
--- | ||
|
||
Allow actions to be called on the server. This allows you to call actions as utility functions in your Astro frontmatter, endpoints, and server-side UI components. | ||
|
||
Import and call directly from `astro:actions` as you would for client actions: | ||
|
||
```astro | ||
--- | ||
// src/pages/blog/[postId].astro | ||
import { actions } from 'astro:actions'; | ||
await actions.like({ postId: Astro.params.postId }); | ||
--- | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
return Astro.rewrite('/subscribe'); | ||
--- |
11 changes: 11 additions & 0 deletions
11
packages/astro/test/fixtures/actions/src/pages/subscribe.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
import { actions } from 'astro:actions'; | ||
const { url, channel } = await actions.subscribeFromServer({ | ||
channel: 'bholmesdev', | ||
}); | ||
--- | ||
|
||
<p data-url>{url}</p> | ||
<p data-channel>{channel}</p> | ||
|