node-serviceworker

Environment for running serviceworkers in node.js, as 'isomorphic' request handlers for clients without SW support.


Keywords
serviceworker, nodejs, isomorphic
License
Apache-2.0
Install
npm install node-serviceworker@0.2.1

Documentation

node-serviceworker

Environment for running serviceworkers in node.js, as 'isomorphic' request handlers for clients without SW support.

Features and status

Based on this task.

  • Registration to a scope. This introduces a very basic routing scope, but finer-grained routing is normally happening inside the service worker.
  • fetch, via https://github.com/gwicke/node-fetch
    • Added ReadableStream support.
    • This also provides a basic Response implementation, wrapping the node HTTP response object.
  • Request wrapper for Node's IncomingMessage.
  • Cache. On the server, this is useful for in-process caching of frequently-used fragments.
  • Accept ReadableStream body responses in FetchEvent.respondWith
  • IndexedDB, via https://github.com/dumbmatter/fakeIndexedDB
  • Runs basic sw-toolbox based ServiceWorkers.
  • Periodic ServiceWorker code refreshs.
  • Per-domain configuration support.

Demo

A demo service based on node-serviceworker-proxy is running at https://swproxy.wmflabs.org/wiki/Foobar. This is serving a demo streaming serviceworker, which composes templates and streamed HTML content using web-stream-util and web-html-stream.

TODO

  • More closely implement WorkerGlobalScope. Roughly in order of importance:
    • console has a lot more methods in browsers than in node
    • location: done
    • performance object: Lots missing.
    • navigator object: Partly done, but more to do.