Skip to content
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

Stream doesn't wrap the evens following the stream format #947

Open
macabeus opened this issue Dec 18, 2024 · 2 comments
Open

Stream doesn't wrap the evens following the stream format #947

macabeus opened this issue Dec 18, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@macabeus
Copy link

macabeus commented Dec 18, 2024

What version of Elysia is running?

1.1.26

What platform is your computer?

Darwin 24.1.0 arm64 arm

What steps can reproduce the bug?

Run any endpoint using the stream feature. For example:

import { Elysia } from 'elysia';

const app = new Elysia()
  .get('/ok', async function* () {
    yield 1;
    yield 2;
    yield 3;
  })
  .listen(3700);

console.log(`🦊 Elysia is running at ${app.server?.hostname}:${app.server?.port}`);

export { app };

Currently, Elysia outputs the following:

> curl -N http://localhost:3700/ok
123

What is the expected behavior?

I think we should format automatically format output following the stream format, since it also sets by default the content type as text/event-stream.
Or, at least, we should have a helper function or flag to toggle it.

It's confusing that we aren't wrapping the message as a client probably expects to be.

The expected output is the following:

> curl -N http://localhost:3700/ok
data: 1

data: 2

data: 3

What do you see instead?

For example, Insomnia and Postman can't read the event streams sent by Elysia, since it is not wrapped in the expected format.

I know that Eden supports the non-standard stream format outputted by Elysia, but I don't except many clients supporting it.

It's specifically bad if you are developing a public API.

Additional information

I can work on it. But firstly, I would like some guidelines and an agreement in how it should be fixed (e.g., add a flag to toggle it, or something else).

@macabeus macabeus added the bug Something isn't working label Dec 18, 2024
@macabeus
Copy link
Author

Nevermind, I noticed that there is already an open PR fixing it
#743

@macabeus
Copy link
Author

Opening back this issue because the author of the original PR might not continue to work on them
#742 (comment)

@macabeus macabeus reopened this Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant