npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sse-stream-auth

v3.0.1

Published

A fork of sse-stream with cookie-based auth support

Downloads

7

Readme

sse-stream-auth

This is a fork of sse-stream that adds cookie-based authentication support & dynamic connection creation

See https://github.com/jameswomack/sse-stream-auth-example.git for an example of using auth and subscribing to multiple channels that you've created dynamically.

Expose HTML5 Server Sent Events as an installable appliance on Node.JS http servers; connections are emitted as Writable streams.


var http = require('http')
  , fs = require('fs')
  , through = require('through')
  , sse = require('sse-stream-auth')({ prefixes: ['/awesomeApp'], create: true }) // Allow dynamic connection creation
  , serv

module.exports = serv = http.createServer(function(req, resp) {
  resp.setHeader('content-type', 'text/html')
  resp.end('<html><body><script type="text/javascript">('+js+')()</script></body></html>')
})

sse.install(serv)

sse.on('connection', function(client) {
  fs.createReadStream('/usr/share/dict/words')
    .pipe(through(function(buf) { this.emit('data', buf.toString()) }))
    .pipe(client)
})

// client-side code:
function js() {
  var es = new EventSource('/awesomeApp/someChannelNameHere')
    , pre = document.createElement('pre')
    , closed = false

  document.body.appendChild(pre)

  es.onmessage = function(ev) {
    if(closed) return

    pre.appendChild(document.createTextNode(ev.data))

    window.scrollTo(0, pre.clientHeight)
  }

  es.addEventListener('end', function() {
    es.close()
    closed = true
  }, true)

  es.onerror = function(e) {
    closed = true
  }
}

API

sse = require('sse-stream-auth')(options)

Create a SSE server that emits connection events on new, successful eventstream connections.

The argument must be an options object:

{ prefixes: ['/awesomeApp', '/awesomeUsername']
, keepalive: 1000 }

keepalive determines the interval time in ms that keepalives will be sent to all connected clients.

sse.on('connection', function(client))

client is a writable stream representing a client connection (request response pair).

Of note, all data sent through this connection will be stringified before sending due to the event stream spec.

client.retry(integer ms)

Send a "retry" message that lets the client know how many MS to wait until retrying a connection that ended.

license

MIT