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

@just-be/wildcard

v0.6.0

Published

Portable wildcard subdomain routing with pluggable storage backends

Readme

@just-be/wildcard

Portable wildcard subdomain routing library with pluggable storage backends. Route subdomains to static files, redirects, or proxied URLs with dependency injection for maximum flexibility.

Features

  • Pluggable storage backends - Use any file storage (R2, S3, filesystem, etc.)
  • Security built-in - SSRF protection, path traversal prevention, safe header filtering
  • Three routing modes:
    • Static - Serve files from any storage backend with SPA mode and custom 404s
    • Redirect - 301/302 redirects to external URLs
    • Rewrite - Proxy requests to external services
  • Framework-agnostic - Works with Cloudflare Workers, Node.js, Deno, Bun, etc.
  • Type-safe - Full TypeScript support with Zod validation

Installation

bun add @just-be/wildcard zod

Quick Start

1. Implement Storage Adapters

import type { FileLoader, RouteConfigLoader } from "@just-be/wildcard";

// Implement your file loader (example with filesystem)
const fileLoader: FileLoader = {
  async loadFile(path: string) {
    try {
      const content = await fs.readFile(path);
      return {
        body: content,
        etag: generateEtag(content),
        headers: new Headers(),
      };
    } catch {
      return null;
    }
  },
};

// Implement your route config loader (example with JSON file)
const routeConfigLoader: RouteConfigLoader = {
  async loadRouteConfig(subdomain: string) {
    try {
      const config = await fs.readFile(`./config/${subdomain}.json`, "utf-8");
      return config;
    } catch {
      return null;
    }
  },
};

2. Use the Handlers

import { handleStatic, handleRedirect, handleRewrite, StaticConfigSchema } from "@just-be/wildcard";

// Load and validate config
const configJson = await routeConfigLoader.loadRouteConfig("myapp");
const config = StaticConfigSchema.parse(JSON.parse(configJson));

// Handle the request - pass dependencies after config
const response = await handleStatic(request, config, fileLoader);

// Handlers without dependencies don't need extra args
const redirectResponse = await handleRedirect(request, redirectConfig);

Configuration Schemas

Static File Serving

import { StaticConfigSchema } from "@just-be/wildcard";

const config = {
  type: "static",
  path: "apps/myapp", // Base path in storage
  spa: true, // Optional: SPA mode (all routes serve index.html)
  fallback: "404.html", // Optional: Custom 404 (only in non-SPA mode)
};

Redirect

import { RedirectConfigSchema } from "@just-be/wildcard";

const config = {
  type: "redirect",
  url: "https://example.com",
  permanent: false, // Optional: 301 vs 302
};

Rewrite (Proxy)

import { RewriteConfigSchema } from "@just-be/wildcard";

const config = {
  type: "rewrite",
  url: "https://api.example.com",
  allowedMethods: ["GET", "POST"], // Optional: defaults to ["GET", "HEAD", "OPTIONS"]
};

Dependency Injection

The library uses dependency injection to decouple from specific storage backends:

interface FileLoader {
  loadFile(path: string): Promise<FileObject | null>;
}

interface RouteConfigLoader {
  loadRouteConfig(subdomain: string): Promise<string | null>;
}

interface FileObject {
  body: ReadableStream<Uint8Array> | ArrayBuffer | null;
  headers?: Headers;
  etag?: string;
  size?: number;
}

Security Features

  • SSRF Protection - Blocks requests to private IPs and localhost
  • Path Traversal Prevention - Sanitizes all file paths
  • Header Filtering - Only forwards safe headers in proxy mode
  • Content Type Detection - Sets correct MIME types
  • Security Headers - Adds CSP, X-Frame-Options, etc.

Example: Cloudflare Workers

See the services/wildcard directory for a complete Cloudflare Workers implementation using R2 and KV.

API Reference

Handlers

  • handleStatic(request, config, fileLoader) - Serve static files from storage
  • handleRedirect(request, config) - Handle URL redirects (301/302)
  • handleRewrite(request, config) - Proxy requests to external services

Schemas

  • StaticConfigSchema - Validates static file config
  • RedirectConfigSchema - Validates redirect config
  • RewriteConfigSchema - Validates rewrite config
  • RouteConfigSchema - Discriminated union of all configs

Utilities

  • sanitizePath(path) - Sanitize file paths
  • isSafeURL(url) - Validate URLs for SSRF
  • getContentType(path) - Detect MIME types
  • filterSafeHeaders(headers) - Filter request headers
  • isValidSubdomain(subdomain) - Validate subdomain format

License

MIT