Express integration: a pre-configured Express app and a WS upgrade
attachment helper that defaults to DNS-rebind protection.
pnpm add @arcp/express @arcp/runtimeimport { createServer } from "node:http";
import { ARCPServer } from "@arcp/runtime";
import { createArcpExpressApp, attachArcpToExpress } from "@arcp/express";
const app = createArcpExpressApp({
allowedHosts: ["arcp.example.com"],
});
app.get("/healthz", (_req, res) => res.send("ok"));
const httpServer = createServer(app);
const arcp = new ARCPServer({
/* … */
});
attachArcpToExpress(httpServer, {
path: "/arcp",
allowedHosts: ["arcp.example.com"],
onTransport: (t) => arcp.accept(t),
});
httpServer.listen(3000);function createArcpExpressApp(options?: CreateArcpExpressAppOptions): Express;Returns a fresh Express app with sane defaults:
x-powered-byremoved.- Optional Host validation middleware.
Most apps that already exist as Express can skip this and just call
attachArcpToExpress on their existing http.Server.
| Field | Default | Notes |
|---|---|---|
disablePoweredBy?: boolean |
true |
Strip X-Powered-By: Express. |
allowedHosts?: readonly string[] |
none | Validate Host on every request. |
Thin wrapper around attachArcpUpgrade from
@arcp/node. Accepts the same options:
| Field | Notes |
|---|---|
path?: string |
Defaults to "/arcp". |
allowedHosts?: readonly string[] |
Recommended for public servers. |
onTransport: (transport, req) => void |
Pair the transport with server.accept. |
Returns an ArcpUpgradeHandle with close().
Use @arcp/express when:
- You're already running Express and want
Hostvalidation applied to both HTTP requests and the WS upgrade. - You want
createArcpExpressAppas a starting point.
Use @arcp/node directly when:
- Your HTTP framework is something else (Fastify, Hono, Koa) and you're just borrowing the upgrade helper.
- You want to wire upgrade behavior manually.