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

@yieldstar/bun-http-server

v0.4.6

Published

## Features

Readme

@yieldstar/bun-http-server

Features

  • Route handlers for triggering and monitoring workflows
  • Middleware for request/response/context processing

Installation

npm install @yieldstar/bun-http-server

Basic Usage

import { createRoutes } from "@yieldstar/bun-http-server";
import { pino } from "pino";

const logger = pino();

const server = Bun.serve({
  port: 3000,
  routes: createRoutes({
    invoker: invoker,
    logger: logger,
    middleware: [middleware1, middleware2],
  }),
});

logger.info(`Server started on port ${server.url}`);

Custom Routes

Bun.serve({
  port: 3000,
  routes: {
    "/status": new Response('OK'),
    // mount workflow routes on /workflow
    ...createRoutes({
      basePath: "/workflow",
      invoker,
      logger,
    }),
  },
});

Middleware

Middleware can be passed to the server. Middleware enables:

  • reading the HTTP request
  • setting context (available to other middleware and the invoked workflow)
  • returning early HTTP responses
  • setting HTTP response headers
import { createRoutes, createMiddleware } from "@yieldstar/bun-http-server";

// CORS middleware
const corsMiddleware = createMiddleware(async (req, event, next) => {
  // Continue to the next middleware or handler
  const response = await next();

  // Add CORS headers to the response
  response.headers.set("Access-Control-Allow-Origin", "*");
  response.headers.set(
    "Access-Control-Allow-Methods",
    "GET, POST, PUT, DELETE, OPTIONS"
  );
  response.headers.set(
    "Access-Control-Allow-Headers",
    "Content-Type, Authorization"
  );

  return response;
});

// Authentication middleware
const authMiddleware = createMiddleware(async (req, event, next) => {
  // Get auth token from request
  const cookies = parseCookies(req.headers.get("Cookie"));
  const authToken = cookies["X-Token"];

  if (!authToken) {
    return new Response("Unauthorized", { status: 401 });
  }

  // Store the auth token in the context
  event.context.set("authToken", authToken);

  // Continue to the next middleware or handler
  return next();
});

// Create server with middleware
const server = Bun.serve({
  port: 8080,
  routes: createRoutes({
    logger,
    invoker,
    middleware: [corsMiddleware, authMiddleware],
  }),
});

Middleware lifecycle

import { createMiddleware } from "@yieldstar/bun-http-server";

const myMiddleware = createMiddleware(async (req, event, next) => {
  // Read the HTTP request
  const token = req.headers.get("X-token");

  // Read context set by previous middlewares
  event.context.get("token");

  // Set context
  if (!token) {
    event.context.set("token", token);
  }

  // Advance the middleware chain until either:
  // A middleware function returns a response,
  // or, the final handler invokes the workflow
  const response = await next();

  // After next() is called, the context is frozen to prevent modifications
  // Any attempt to modify the context will throw an error:
  event.context.set("key", "value"); // Error: Cannot call set on a frozen map

  // When passed to the workflow, the context is converted to a read-only version
  // that prevents modifications in the workflow

  // The response can still be updated before it is sent to the user
  response.headers.set("X-Handled-By", "SuperAceDev");

  return response;
});

API Reference

createRoutes(options)

Creates an HTTP server for YieldStar workflows.

Options:

  • invoker: The workflow invoker
  • logger: A Pino logger instance
  • middleware: Optional array of middleware functions
  • basePath: Optional path to mount the routes on

createMiddleware(handler)

Creates a middleware function.

Handler parameters:

  • req: The request object
  • event: The middleware event with a context property (Map)
  • next: Function to call the next middleware or handler
  • logger: The logger passed to createRoutes

License

MIT