-
Notifications
You must be signed in to change notification settings - Fork 458
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
Add a Usage example for SSE in the docs #2374
Comments
Thanks for the issue ❤️ Feel free to contribute to the docs by making a PR. |
@pi0 To be honest, I am not entirely sure what the usage should be. You mentioned that the usage is the same as in h3 but in a Nuxt/Nitro server route there is usually some kind of an event handler like in the example of @Atinux SSE endpoint example with Nuxt 3 gist // ~/server/api/sse.ts
export default defineEventHandler(async (event) => {
// ...
}) And then the client can connect to the route endpoint // client code
const sse = new EventSource('/api/sse') |
Simply like this https://stackblitz.com/edit/github-lku74j?file=server%2Froutes%2Findex.ts And you can either render it directly or connect with an eventsource client. you can also use |
Works like a charm, tested also with Nuxt. I will send in pull request to update the docs. Pull Request: #2379 |
Have an example of SSE working here in a real world app if that's beneficial at all: Has some stuff around Auth too and creating unique sessions for if you don't want all the events on every SSE connection. |
Describe the feature
Currently in the docs there is a Usage example for how to create a WebSocket Nitro route: https://nitro.unjs.io/guide/websocket#usage but there is no example for server-sent events and how to create a Nuxt/Nitro route for that. There is an example in h3 docs but not in Nitro.
It would be very useful to create such usage example also for SSE (Server-sent events) just like WebSockets example.
Additional information
The text was updated successfully, but these errors were encountered: