Skip to content

Commit

Permalink
Merge pull request #303 from OrJDev/main
Browse files Browse the repository at this point in the history
server functions: allow get requests
  • Loading branch information
nksaraf authored Jun 17, 2024
2 parents e9f6a23 + 0d6b09b commit 9b490b7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/tiny-items-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@vinxi/server-functions": patch
"vinxi": patch
---

server functions: allow get requests
10 changes: 7 additions & 3 deletions packages/vinxi-server-functions/server-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { eventHandler, getHeader, readBody, setHeader } from "vinxi/http";
import invariant from "vinxi/lib/invariant";
import { getManifest } from "vinxi/manifest";

export async function handleServerAction(event) {
invariant(event.method === "POST", "Invalid method");
const allowedMethods = ["POST", "GET"];

export async function handleServerAction(event) {
invariant(allowedMethods.includes(event.method), "Invalid method");
const serverReference = getHeader(event, "server-action");
if (serverReference) {
invariant(typeof serverReference === "string", "Invalid server action");
Expand All @@ -14,7 +15,10 @@ export async function handleServerAction(event) {
const action = (
await getManifest(import.meta.env.ROUTER_NAME).chunks[filepath].import()
)[name];
const json = await readBody(event);
let json = {};
if (event.method === "POST") {
json = await readBody(event);
}
const result = action.apply(null, json);
try {
// Wait for any mutations
Expand Down

0 comments on commit 9b490b7

Please sign in to comment.