Skip to content

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

@macabeus

Description

@macabeus

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions