Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fastify-sse-v2

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify-sse-v2 - npm Package Compare versions

Comparing version 2.0.3 to 2.0.4

6

CHANGELOG.md

@@ -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 @@

3

lib/plugin.js

@@ -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");

6

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc