fastify / fastify/light-my-request
Support server-sent events
- Dominant language
- JavaScript
- Stars
- 420
- Forks
- 55
- Avg merge
- 13d 14h
- Merged PRs (30d)
- 1
Description
### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the feature has not already been requested
### 🚀 Feature Proposal
I would like this module to support [server-sent events (SSE)](https://html.spec.whatwg.org/multipage/server-sent-events.html#the-eventsource-interface).
(If helpful, I can submit a pull request.)
### Motivation
Currently, the best way to test SSE doesn't use this package at all. It seems the state-of-the-art is to start the server and use an `EventSource`, possibly with the [eventsource package](https://www.npmjs.com/package/eventsource). This works but requires the server to be active, which this module tries to avoid.
It would be nice if this package had an answer for testing SSE.
This was briefly discussed in #105.
### Example
There are several possible ways this API could be implemented. My favorite idea is a re-implementation of the W3C `EventSource`; something like this:
```javascript
const source = new inject.EventSource(dispatch, { path: '/my-events' })
source.onmessage = (event) => {
console.log(event)
if (event.data === 'please close') {
source.close()
}
}
```
But there are many possible options, which we can discuss (if we even want to implement this feature at all!).
Contributor guide
Assessment
This issue has not been assessed yet.