Why I rewrote `sirv` for Edge Runtimes (and added a plugin system)
DEV Community

Why I rewrote sirv for Edge Runtimes (and added a plugin system)

Lukeed's sirv is legendary, but the edge runtime landscape has shifted. We need zero-copy streaming, native Web APIs, and composable transforms without pulling in Node-specific shims. Enter @rabbx/sirv. It's an ultra-fast, zero-dependency static file middleware for Bun, Deno, Node.js, and Cloudflare Workers.

The Problem with Existing Middleware

Most static servers are built for Node.js. When you try to run them on Deno or CF Workers, you end up polyfilling half the Node standard library, which kills performance and bloats the bundle.

The Solution: Edge-Native & Composable

@rabbx/sirv uses native Web APIs (Request, Response, ReadableStream) from the ground up. But the real unlock is the plugin system. Instead of a rigid middleware chain, you get composable setHeaders and transform hooks with ordering and conditions.

Here's how easy it is to build a Markdown-to-HTML static site generator in 20 lines of code:

import { sirv, plugin } from '@rabbx/sirv';
import { marked } from 'marked';

const markdown = plugin({
  name: 'markdown',
  test: ctx => ctx.path.endsWith('.md'),
  transform: async (stream, ctx) => {
    const html = marked.parse(await new Response(stream).text());
    ctx.headers.set('Content-Type', 'text/html; charset=utf-8');
    ctx.headers.delete('Content-Length'); // Let the runtime handle it
    return `<!DOCTYPE html><html><body>${html}</body></html>`;
  }
});

Bun.serve({
  port: 3000,
  fetch: sirv('posts', {
    extensions: ['md'],
    plugins: [markdown]
  })
});

Performance

Because it relies on zero-copy streaming on Bun and avoids buffer allocations, you're looking at ~95k req/s with 0.3ms latency. It's MIT, zero deps, and ready for production.

Check out the repo: github

Comments

No comments yet. Start the discussion.