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
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>
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.
6
+
7
+
Import and call directly from `astro:actions` as you would for client actions:
* @param {*} clientParam argument passed to the action when used on the client.
46
-
* @param {string} path Built path to call action on the server.
47
-
* Usage: `actions.[name](clientParam)`.
45
+
* @param {*} param argument passed to the action when called server or client-side.
46
+
* @param {string} path Built path to call action by path name.
47
+
* Usage: `actions.[name](param)`.
48
48
*/
49
-
asyncfunctionactionHandler(clientParam,path){
49
+
asyncfunctionactionHandler(param,path){
50
+
// When running server-side, import the action and call it.
50
51
if(import.meta.env.SSR){
51
-
thrownewActionError({
52
-
code: 'BAD_REQUEST',
53
-
message:
54
-
'Action unexpectedly called on the server. If this error is unexpected, share your feedback on our RFC discussion: https://github.com/withastro/roadmap/pull/912',
0 commit comments