@sarcio/middleware
v0.3.1
Published
Connects a Node.js web application to Sarcio: Express, Fastify, Koa, Hono and node:http.
Readme
@sarcio/middleware
Connects a Node.js web application to Sarcio, so an
approved server-side fix takes effect on a running app without a deploy. It
works with the Sarcio sidecar running on the same host, and has adapters for
Express, Fastify, Koa, Hono and plain node:http.
Setup guides and the full reference are in the Sarcio docs.
Install
npm install @sarcio/middlewareimport { createProtocolShim, ProtocolShimClient } from '@sarcio/middleware';
const client = new ProtocolShimClient({
target: { socketPath: '/run/sarcio/sarcio.sock' },
siteKey
});
await client.start();
app.use(express.json());
app.use(createProtocolShim(client));Framework adapters
| Framework | Adapter | Notes |
| --------------- | -------------------------------------- | ---------------------------------------------- |
| Express | createProtocolShim(client) | read the fix context with sarcioContext(req) |
| Fastify | createProtocolFastifyHook(client) | add as a global preHandler hook |
| Koa | createProtocolKoaMiddleware(client) | register after your body parser |
| Hono | createProtocolHonoMiddleware(client) | |
| raw node:http | withProtocolSarcio(client, listener) | wraps your request listener |
Safe by default
- A request to a route with no active fix does no extra work beyond an in-memory lookup.
- If the sidecar is unreachable, slow or returns anything unexpected, the request runs exactly as it would without Sarcio. The client reconnects by itself when the sidecar comes back.
Authorization,Cookieand other credential headers never leave your application, and request bodies are size-capped.
License
Business Source License 1.1: production use to connect your own applications to a Sarcio subscription or trial is granted; offering a competing service is not. Each version converts to Apache-2.0 four years after its release.
