Silgi

Overview

Extend Silgi with CORS, distributed tracing, structured logging, rate limiting, and more.

Silgi plugins are just regular middleware and hooks. There is no special plugin API — a "plugin" is a guard, a wrap, or a set of lifecycle hooks that someone has packaged up for reuse.

All plugins ship as subpath imports from the silgi package. You only import what you use, and unused plugins add zero bytes to your bundle.

You can build your own plugins the same way. A guard that checks a feature flag, a wrap that logs slow queries, a set of hooks that track metrics — they all follow the same patterns described in the Middleware and Server docs.

Plugin types at a glance

PluginTypeHow to use
CacheWrap middlewareAdd cacheQuery(...) for response caching with SWR
CORSHeader helperCall corsHeaders() to get a headers object
OpenTelemetryWrap middlewareAdd otelWrap(tracer) to a procedure's use array
Pino LoggingLifecycle hooksPass loggingHooks({ logger }) to the hooks option
Rate LimitingGuard middlewareAdd rateLimitGuard(...) to a procedure's use array
Body LimitGuard middlewareAdd bodyLimitGuard(...) to reject oversized payloads
Strict GETGuard (singleton)Add strictGetGuard to enforce GET on queries
CookiesHelper functionsUse getCookie(), setCookie(), deleteCookie()
SigningHelper functionsUse sign(), unsign(), encrypt(), decrypt()
Smart CoercionGuard (singleton)Add coerceGuard to auto-convert string inputs
Server BatchHandler factoryUse createBatchHandler() for batch endpoint
Publisher/PubSubEvent systemUse createPublisher() + MemoryPubSub or Redis
File UploadGuard middlewareUse fileGuard() + parseMultipart() for uploads

Ecosystem packages

Silgi re-exports key UnJS packages. No extra pnpm add needed — import directly from silgi/*:

Import fromPackageUse case
silgi/unstorageunstorageKey-value storage (Redis, KV, S3, etc.)
silgi/ocacheocacheCached functions with TTL + SWR
silgi/ofetchofetchUniversal fetch with auto-retry
silgi/srvxsrvxUniversal server (Node, Deno, Bun)
import {  } from 'silgi/unstorage'
import {  } from 'silgi/ofetch'
import {  } from 'silgi/srvx'

What's next?

  • Middleware — understand guards and wraps, which power most plugins
  • Server — lifecycle hooks, which power the logging plugin

On this page