MatthewWid / better-sse

⬆ Dead simple, dependency-less, spec-compliant server-sent events implementation for Node, written in TypeScript.
https://matthewwid.github.io/better-sse/
MIT License
559 stars 14 forks source link

How can we pass headers #63

Closed dpvenkatesh closed 6 months ago

dpvenkatesh commented 6 months ago

Can you add an example of passing Authorization headers while connecting to see from the client.

MatthewWid commented 6 months ago

This library manages the server-end of SSE, only.

If you want to be able to send headers from the client you should use an EventSource library that allows you to do so. EventSource/eventsource and Yaffle/EventSource are two good options.

For example, using EventSource/eventsource:

const eventsource = new EventSource(
  "/sse",
  {
    headers: {
      Authorization: "<content>"
    }
  }
);