Dex

Server

Server

@dex/server provides Elysia plugins and runtime utilities for static asset delivery, SSG-aware SPA fallback, subdomain canonical redirects, server-side <head> and Google Fonts injection, dev live-reload, logging, public env extraction, and port discovery.

Topics

  • Serving Assets — Static file serving at /assets/*
  • SPA Fallback — Request pipeline, SSG lookup, subdomains, <head> metadata, and fonts
  • Dev Reload — SSE live reload in development
  • Logging — Request logging with dexPrettyLogger
  • Production — Standalone binary, Google Fonts @theme, getPublicEnvDefines, and port helpers

Quick Start

# Dev server
bun run dev

# Production build (outputs standalone build/server binary + assets + SSG HTML)
bun run build

# Run production server
cd build
./server

Google Fonts & Variable Fonts

Configure Google Fonts once in dex.config.ts:

// dex.config.ts
export default {
  mode: 'spa',
  renderStrategy: 'ssg',
  fonts: {
    sans: 'Inter',
    mono: { family: 'JetBrains Mono', weights: '100..800' },
  },
}

Both dexSpaFallback (at request time) and dexPrerender (at build time) automatically read fonts from dex.config.ts and inject <link rel="preconnect">, the Google Fonts CSS2 <link rel="stylesheet">, CSS custom properties (--font-sans, --font-mono), and .font-sans / .font-mono utility classes into <head>. @dex/server also exports buildGoogleFontsUrl, injectGoogleFonts, generateFontThemeCss, DexFontSpec, and DexFontsConfig for custom pipelines and Tailwind v4 @theme generation.

Key Features

FeatureAPIPurpose
Asset ServingdexAssetsRouteStatic files and ESM chunks from /assets/* with traversal protection
SPA & SSG FallbackdexSpaFallbackServes prerendered SSG HTML or index.html, handles 308 subdomain redirects, injects <head> & fonts
Dev ReloaddexDevReloadRouterSSE reload stream at /__dev/reload in development
Request LoggingdexPrettyLoggerColorized TTY / plain production HTTP & error logs
Google FontsinjectGoogleFonts, buildGoogleFontsUrl, generateFontThemeCssVariable & static Google Fonts injection and Tailwind v4 @theme CSS
Public Env & PortsgetPublicEnvDefines, findAvailablePort, isPortAvailableSafe client env --define flags and dynamic port binding up to 65535

See Also

On this page