fastify-sse-v2
Advanced tools
Comparing version 2.0.3 to 2.0.4
@@ -8,2 +8,8 @@ # Changelog | ||
## [Unreleased] | ||
## [2.0.4] | ||
## Fixed | ||
- headers from reply (other plugins like cors) not being set on stream | ||
- vulnerable dependencies | ||
## [2.0.3] | ||
@@ -10,0 +16,0 @@ |
@@ -16,2 +16,5 @@ "use strict"; | ||
instance.decorateReply("sse", function (source) { | ||
Object.entries(this.getHeaders()).forEach(([key, value]) => { | ||
this.raw.setHeader(key, value); | ||
}); | ||
this.raw.setHeader("Content-Type", "text/event-stream"); | ||
@@ -18,0 +21,0 @@ this.raw.setHeader("Connection", "keep-alive"); |
{ | ||
"name": "fastify-sse-v2", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "Fastify plugin for sending server side events.", | ||
@@ -42,3 +42,3 @@ "main": "lib/index.js", | ||
"@types/eventsource": "^1.1.2", | ||
"@types/mocha": "^5.2.5", | ||
"@types/mocha": "^8.2.2", | ||
"@types/sinon": "^9.0.0", | ||
@@ -55,3 +55,3 @@ "@typescript-eslint/eslint-plugin": "^1.3.0", | ||
"it-pushable": "^1.4.0", | ||
"mocha": "^6.1.4", | ||
"mocha": "^8.3.2", | ||
"sinon": "^9.0.2", | ||
@@ -58,0 +58,0 @@ "ts-node": "^8.3.0", |
@@ -42,2 +42,3 @@ # Fastify SSE Plugin | ||
Using EventIterator dependency: | ||
```javascript | ||
@@ -62,2 +63,25 @@ import {FastifySSEPlugin} from "fastify-sse-v2"; | ||
Without additional dependency ([not supported in all nodejs versions](https://nodejs.org/api/events.html#events_events_on_emitter_eventname_options): | ||
```javascript | ||
import {FastifySSEPlugin} from "fastify-sse-v2"; | ||
import {on} from "events"; | ||
const server = fastify(); | ||
server.register(FastifySSEPlugin); | ||
server.get("/", function (req, res) { | ||
res.sse( | ||
(async function* () { | ||
for await (const event of on(eventEmmitter, "update")) { | ||
yield { | ||
type: event.name, | ||
data: JSON.stringify(event), | ||
}; | ||
} | ||
})() | ||
); | ||
}); | ||
``` | ||
##### Note | ||
@@ -64,0 +88,0 @@ - to remove event listeners (or some other cleanup) when client closes connection, |
@@ -11,2 +11,5 @@ import {EventMessage, FastifyPluginAsync, FastifyReply} from "fastify"; | ||
function (this: FastifyReply, source: AsyncIterable<EventMessage>): void { | ||
Object.entries(this.getHeaders()).forEach(([key, value]) => { | ||
this.raw.setHeader(key, value); | ||
}); | ||
this.raw.setHeader("Content-Type","text/event-stream"); | ||
@@ -13,0 +16,0 @@ this.raw.setHeader("Connection", "keep-alive"); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18897
200
89