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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@polytric/fastify-openws-ui

v0.0.4

Published

Polytric OpenWS UI plugin for Fastify

Readme

fastify-openws-ui

npm license

@polytric/fastify-openws-ui integrates OpenWS UI into a Fastify server.

It:

  • serves the OpenWS UI web app under a configurable prefix (default: /openws/)
  • exposes your generated OpenWS spec JSON (default: /openws/spec.json)
  • automatically collects OpenWS networks from your Fastify routes (via an onRoute hook)
  • injects runtime config into the UI entry HTML so the UI knows:
    • where the spec is (specUrl)
    • which roles are "host" roles per network (networkHosts), used for connect presets

Install

npm i @polytric/fastify-openws-ui

You will typically also use this alongside:

npm i @polytric/fastify-openws @polytric/openws @polytric/openws-spec @fastify/static

This plugin will register the OpenWS Fastify plugin automatically if it's not already present on the Fastify instance.


Quick start

import Fastify from 'fastify'
import openwsUi from '@polytric/fastify-openws-ui'

const app = Fastify()

await app.register(openwsUi, {
    name: 'My Service',
    prefix: '/openws', // optional (default: "/openws")
    exportPath: '/spec.json', // optional (default: "/spec.json")
})

// Define your OpenWS-enabled routes here…

await app.listen({ port: 8080 })

// UI:   http://localhost:8080/openws/
// Spec: http://localhost:8080/openws/spec.json

How it discovers networks

This plugin watches routes as they are registered:

  • If a route has an attached openWsNetwork (a Network from @polytric/openws-spec/builder), it will:
    • add that network to the generated spec
    • record "host roles" (roles where role.isHost === true) into networkHosts[network.name]

This enables OpenWS UI to show:

  • network selection (if multiple)
  • role/message navigation
  • connect presets for host roles

Expected route shape (conceptual)

The plugin looks for an openWsNetwork field on route options at registration time:

import type { Network } from "@polytric/openws-spec/builder";

const myNetwork: Network = /* build your network via openws/openws-spec tooling */;

app.get("/chat", {
  // your OpenWS route config/handler…
  openWsNetwork: myNetwork,
}, async (_req, reply) => {
  reply.send("ok");
});

The exact way you attach networks depends on @polytric/fastify-openws / your OpenWS route setup. The important part for UI/spec export is that openWsNetwork is present in the route options when the route is registered.


Plugin options

interface PluginOptions {
    prefix: string // where to mount the UI + spec endpoints (default "/openws")
    exportPath: string // spec JSON path relative to prefix (default "/spec.json")
    name: string // spec name, used when creating the OpenWS spec
}

Defaults (as implemented):

  • prefix: /openws
  • exportPath: /spec.json

Routes added

Assuming defaults:

  • GET /openws/spec.json
    Returns the generated OpenWS spec JSON.

  • GET /openws
    Redirects to /openws/ (trailing slash).

  • GET /openws/
    Serves index.html with injected runtime config:

    {
        "specUrl": "/openws/spec.json",
        "networkHosts": {
            "Chat": ["Server"]
        }
    }
  • Static assets served under:
    GET /openws/* (from openwsUiRoot via @fastify/static)


Runtime validation (development)

When NODE_ENV === "development", the exported spec is validated using:

  • validate() from @polytric/openws-spec

If validation fails, it logs spec is invalid and throws.


Decorators

This plugin decorates the Fastify instance with:

fastify.openwsUi.getSpec(): JsonObject

That allows you to programmatically retrieve the spec (for tests, CI export, etc.).


Example: Export the spec at startup

import fs from 'node:fs'

app.ready(() => {
    const spec = app.openwsUi.getSpec?.()
    if (spec) fs.writeFileSync('./openws-spec.json', JSON.stringify(spec, null, 2))
})

License

Licensed under the Apache License 2.0. See LICENSE.