npm.io
1.0.1 • Published 3h ago

@appport/server

Licence
Apache-2.0
Version
1.0.1
Deps
3
Size
113 kB
Vulns
0
Weekly
0

@appport/server

The server-side protocol runtime and its web bindings.

import { createServer } from "@appport/server";
import { serve } from "@appport/server/node";

const server = createServer({
  application,
  authenticate: ({ sessionId }) => sessions.resolve(sessionId)
});

const running = await serve({ server, port: 4400, cors: { origins: "*" } });

serve exposes, against one capability server:

Route Purpose
POST /appport requests, and streams as NDJSON
GET /appport/events events as Server-Sent Events
GET /appport/manifest the manifest
GET /.well-known/appport discovery
WS /appport/ws the WebSocket binding

The WebSocket endpoint is a dependency-free RFC 6455 implementation: framing, fragmentation, ping/pong and close, with one AppPort envelope per message.

AppPortConnection is the duplex half used by WebSocket, IPC and in-process transports. It owns subscription and stream bookkeeping, so unsubscribe releases resources and cancellation reaches the handler.

For edge runtimes, createFetchHandler(binding) returns a standard (Request) => Promise<Response>.

authenticate resolves an identity from transport-supplied credentials. AppPort does not authenticate; it represents the resulting identity, and authorizes every capability regardless of which transport delivered it.