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

@davaux/multisite

v0.8.1

Published

Multi-site hosting for Davaux — run multiple sites from a single codebase

Readme

@davaux/multisite

Multi-site hosting for Davaux — run multiple sites from a single process, dispatched by Host header.

Installation

npm install @davaux/multisite

Basic setup

// server.ts
import { startMultisite } from '@davaux/multisite'

startMultisite({
  sites: [
    {
      name: 'main',
      hostname: 'example.com',
      routesDir: './src/routes/main',
    },
    {
      name: 'blog',
      hostname: 'blog.example.com',
      routesDir: './src/routes/blog',
    },
  ],
}, { port: 3000, cwd: import.meta.dirname })

startMultisite auto-detects NODE_ENV — dev mode with file watching and live reload when NODE_ENV !== 'production', production dispatch otherwise. Pass cwd: import.meta.dirname from your server.ts for reliable path resolution.

Shared base + per-site overlay

Use baseDir for routes shared across all sites. Each site's routesDir overlays on top — when both define the same URL pattern and type, the site-specific route wins:

startMultisite({
  baseDir: './src/routes/base',
  islandsDir: './src/islands/base',
  publicDir: './public',
  sites: [
    { name: 'tenant-a', hostname: 'a.example.com', routesDir: './src/routes/tenant-a' },
    { name: 'tenant-b', hostname: 'b.example.com', routesDir: './src/routes/tenant-b' },
    { name: 'fallback', hostname: '*' },
  ],
}, { cwd: import.meta.dirname })

'*' as hostname is a catch-all for any host not explicitly registered.

Per-site config

Attach arbitrary data to each site via SiteDefinition.config. Access it in any handler, layout, or middleware via getSite<T>(ctx):

import { getSite } from '@davaux/multisite'

// In server.ts:
startMultisite({
  sites: [
    { name: 'acme', hostname: 'acme.example.com', config: { theme: 'blue', name: 'Acme' } },
    { name: 'globex', hostname: 'globex.example.com', config: { theme: 'red', name: 'Globex' } },
  ],
})

// In any route file:
export default definePage((ctx) => {
  const site = getSite<{ theme: string; name: string }>(ctx)
  return <h1>Welcome to {site?.name}</h1>
})

getSite returns undefined when called outside a multisite server (e.g. in tests).

SiteDefinition options

| Option | Type | Description | |---|---|---| | name | string | Unique site identifier used in logging and asset paths | | hostname | string \| string[] | Host header value(s) that route to this site. '*' is a catch-all | | routesDir | string? | Site-specific routes directory, overlaid on baseDir | | islandsDir | string? | Site-specific islands directory, merged with shared islandsDir | | publicDir | string? | Site-specific static files directory (takes priority over shared publicDir) | | clientEntry | string? | Site-specific client bundle entry. Overrides shared clientEntry | | config | T? | Arbitrary per-site data, accessible via getSite<T>(ctx) |

MultisiteConfig options

| Option | Type | Description | |---|---|---| | sites | SiteDefinition[] | Site definitions (required) | | baseDir | string? | Shared base routes directory | | islandsDir | string? | Shared islands directory — included in every site's client bundle | | publicDir | string? | Shared static files directory | | clientEntry | string? | Shared client bundle entry compiled to /_davaux/client.js |

Production build

// build.ts
import { buildMultisite } from '@davaux/multisite/build'

await buildMultisite({
  sites: [
    { name: 'main', hostname: 'example.com', routesDir: './src/routes/main' },
  ],
}, { cwd: import.meta.dirname })

Compiles all route files, per-site island bundles, and server.ts / multisite.config.ts to dist/. Run with node dist/server.js.

Advanced: embedding in a custom server

import { buildMultisiteApps, dispatchToSite } from '@davaux/multisite'
import { createServer } from 'node:http'

const apps = await buildMultisiteApps(config, { cwd: import.meta.dirname })

const server = createServer(async (req, res) => {
  const handled = await dispatchToSite(apps, req, res)
  if (!handled) { res.writeHead(404); res.end('No site') }
})

TypeScript

Use defineSites<T> to get type inference on SiteDefinition.config without a type annotation at every call site:

import { defineSites } from '@davaux/multisite'

interface SiteConfig { theme: string }

export const sites = defineSites<SiteConfig>({
  sites: [
    { name: 'acme', hostname: 'acme.example.com', config: { theme: 'blue' } },
  ],
})

Documentation

davaux.codeberg.page/docs/multisite