Silgi

Express

Mount Silgi as Express middleware — run RPC and REST routes on the same server.

If you have an existing Express application, Silgi can be mounted as middleware alongside your REST routes.

Setup

import  from 'express'
import {  } from 'silgi/express'

const  = ()
.(.()) // Required for POST body parsing

// Existing routes
.('/api/health', (, ) => .({ : 'ok' }))

// Silgi RPC under /rpc
.(
  '/rpc',
  (appRouter, {
    : () => ({
      : getDB(),
      : .user,
      : .ip,
    }),
  }),
)

.(3000)

Context from Express

The context function receives the Express request object. Bridge your existing auth middleware, IP detection, and headers:

createHandler(appRouter, {
  : () => ({
    : .user, // from passport or similar
    : .ip,
    : .headers,
  }),
})

Route behavior

  • Procedures are matched by the path after the mount prefix
  • POST /rpc/users/list → calls users.list with the JSON body as input
  • GET /rpc/users/list?data={"limit":10} → calls users.list with parsed query data
  • Unmatched paths pass through to the next Express middleware (next())

Make sure express.json() middleware is registered before the Silgi middleware — otherwise POST bodies won't be parsed.

What's next?

  • Server — standalone serve() as an alternative
  • Integrations — other available integrations

On this page