-
-
Notifications
You must be signed in to change notification settings - Fork 719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Start: createServerFn cannot return raw response objects #2779
Labels
start
Everything about TanStack Start
Comments
SeanCassiere
added
types
Changes to the typescript types
start
Everything about TanStack Start
and removed
types
Changes to the typescript types
labels
Nov 16, 2024
a temporary solution: async function handleResponse<ResponseBody = unknown>(response: Response): Promise<ResponseBody> {
const event = getEvent()
setHeaders(event, Object.fromEntries(response.headers))
switch (response.headers.get('Content-Type')) {
case 'application/json':
return response.json() as ResponseBody
default:
return response.body as ResponseBody
}
} |
Tried https://discord.com/channels/719702312431386674/1310732156561260575/1310785299915346100 const exampleStreamingFn = createServerFn({ method: 'GET' }).handler(async () => {
const encoder = new TextEncoder();
// replace with ur actual stream
const stream = new ReadableStream({
async start(controller) {
for (let i = 0; i < 10; i++) {
const chunk = encoder.encode(`${i + 1}`);
controller.enqueue(chunk);
await new Promise((resolve) => setTimeout(resolve, 100));
}
controller.close();
},
});
const res = new Response(stream, { status: 200 });
return sendWebResponse(getEvent(), res);
}); and https://discord.com/channels/719702312431386674/1310732156561260575/1310785660948578355 const res = await fetch(exampleStreamingFn.url); Which got streaming kindof working, but after stream is done im getting.
and then vinxi crashes and I need to restart the server |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Which project does this relate to?
Start
Describe the bug
Server functions should able to return Raw Response objects.
Your Example Website or App
https://github.com/nekochan0122/tanstack-start-return-response-object
Steps to Reproduce the Bug or Issue
Expected behavior
{ hello: "world" }
test=test
Screenshots or Videos
No response
Platform
Additional context
No response
The text was updated successfully, but these errors were encountered: