host-router

Routes requests to multiple apps by domain, subdomain, or path prefix patterns.

Updated Nov 7, 2025
One-click install
npx skills add https://github.com/rangojs/rango --skill host-router-rangojs
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: host-router
Source: https://github.com/rangojs/rango/tree/main/packages/rangojs-router/skills/host-router
Command: npx skills add https://github.com/rangojs/rango --skill host-router-rangojs

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @rangojs/router.

What problem does it solve? Running multiple applications behind one domain or across subdomains requires dispatching each incoming request to the correct app based on its hostname. This Skill implements that host-based routing layer for Rango apps, including lazy sub-app loading, middleware, and development-time host overrides. ## Core Features & Use Cases - Pattern-based host matching: Register wildcard patterns like admin.*, **.example.com, or example.com/api and map each to an inline handler or a lazily imported sub-app. - Middleware and fallback handling: Attach global or per-route middleware, configure a fallback for cookie-override errors, and catch NoRouteMatchError for unmatched hosts. - Cookie-based host override for development: Route requests to different apps from a single domain using a validated cookie, with optional custom validation logic. - Use Case: A team serves a marketing site, an admin dashboard, and an API from one Cloudflare Worker or Vercel function, dispatching by subdomain while testing each app locally via a dev cookie. ## Quick Start Create a host router that routes admin subdomain requests to the admin app and all other requests to the main app.

Frequently Asked Questions about host-router

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I route requests to multiple apps by subdomain?

Create a host router with createHostRouter and register host patterns like admin.* or api.*, each mapped via .lazy() to a sub-app module. Incoming requests are matched against patterns in registration order, and the first match handles the request.

What is the difference between .map and .lazy in host routing?

Use .map for an inline handler that returns a Response directly, and .lazy for a dynamic import of a sub-app handler or nested host router. Passing a lazy import to .map is a type error because a module is not a Response.

Does the host router work on Vercel and Node, not just Cloudflare?

Yes, but the export shape differs. On Cloudflare you export a fetch handler that calls router.match; on node and vercel presets you export the HostRouter instance itself so the generated RSC entry can call hostRouter.match for you.

How do I handle requests that match no host pattern?

Unmatched hosts throw NoRouteMatchError. On Cloudflare, catch it in your worker fetch using the isNoRouteMatchError guard and return a 404; on node and vercel presets, the generated entry catches it and returns 404 by default.

Can I test different host routes locally from one domain?

Yes, configure hostOverride with a cookie name and allowedHosts. When the cookie is present and the request host is allowed, the cookie value is used as the effective hostname, letting you exercise different host routes during development.