Skip to content

Commit

Permalink
formar
Browse files Browse the repository at this point in the history
  • Loading branch information
nksaraf committed Nov 5, 2023
1 parent 98ca2f1 commit 9cae3ab
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/vinxi-server-functions/server-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ export async function handleServerAction(event) {
invariant(typeof serverReference === "string", "Invalid server action");
// This is the client-side case
const [filepath, name] = serverReference.split("#");
const action = (await import.meta.env.MANIFEST[import.meta.env.ROUTER_NAME].chunks[filepath].import())[name];
const action = (
await import.meta.env.MANIFEST[import.meta.env.ROUTER_NAME].chunks[
filepath
].import()
)[name];
const text = await new Promise((resolve) => {
const requestBody = [];
event.node.req.on("data", (chunks) => {
Expand All @@ -32,7 +36,13 @@ export async function handleServerAction(event) {
return JSON.stringify(response ?? null);
} catch (x) {
console.error(x);
return { error: x.message }
return new Response(JSON.stringify({ error: x.message }), {
status: 500,
headers: {
"Content-Type": "application/json",
"x-server-function": "error",
},
});
}
} else {
throw new Error("Invalid request");
Expand Down

0 comments on commit 9cae3ab

Please sign in to comment.