MatthewWid / better-sse

⬆ Dead simple, dependency-less, spec-compliant server-sent events implementation for Node, written in TypeScript.
MIT License
485 stars 14 forks source link

How can we pass headers #63

Closed dpvenkatesh closed 3 months ago

dpvenkatesh commented 3 months ago

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

MatthewWid commented 3 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>"
    }
  }
);