Skip to content

Express Adapter

@monque/management-express is the first Management Adapter. It is a thin Express package that mounts the oRPC OpenAPI HTTP handler from @monque/management, passes Express-derived request context into Management hooks, and serves OpenAPI JSON for the mounted API.

The adapter does not define Management routes, schemas, operation IDs, capabilities, authentication, Dashboard assets, or Swagger/Scalar UI. Those responsibilities stay with @monque/management, the host application, or future packages.

bun add @monque/management-express @monque/management @monque/core express

@monque/core, @monque/management, express, and mongodb are peer dependencies.

import { Monque } from '@monque/core';
import { createManagementExpressRouter } from '@monque/management-express';
import express from 'express';
import { MongoClient } from 'mongodb';

const app = express();
const client = new MongoClient('mongodb://localhost:27017');
await client.connect();

const monque = new Monque(client.db('monque'));

app.use(
	'/monque',
	requireOperator,
	createManagementExpressRouter({
		monque,
		context: ({ req }) => ({
			userId: req.get('x-user-id') ?? 'anonymous',
		}),
		authorize: ({ action, context }) => {
			return context.userId !== 'anonymous' || action === 'read';
		},
	}),
);

When mounted at /monque, the Management API is served under /monque/api/v1/*. Authentication remains host-owned: mount authentication or session middleware before the Management router. See createManagementExpressRouter() and ManagementExpressRouterOptions for the full adapter API.

The adapter serves OpenAPI JSON generated by @monque/management. By default it is exposed at /openapi.json relative to the mount path:

/monque/openapi.json

Configure the OpenAPI path and server URL when the public mount differs from the Express route:

app.use(
	'/internal/management',
	createManagementExpressRouter({
		monque,
		openApi: {
			path: '/docs/openapi.json',
			serverUrl: 'https://ops.example.com/internal/management',
		},
	}),
);

Set openApi: false when the host application should expose the document itself. The context option accepts a ManagementExpressContextFactory when authorization or payload serialization needs request-specific state.

Express is the first adapter because it proves the Management Adapter boundary with a common Node.js HTTP framework. Future framework-specific management packages should follow the same shape:

  • depend on @monque/management instead of redefining routes or schemas
  • mount the oRPC OpenAPI HTTP handler as an opaque handler
  • pass framework request context into Management authorization and payload serialization hooks
  • leave authentication to the host application
  • serve adapter-owned OpenAPI metadata such as server URL and OpenAPI JSON path

Future Ts.ED management support should ship as a separate Management Adapter package such as @monque/management-tsed. The existing @monque/tsed package stays focused on dependency injection, decorators, and scheduler lifecycle integration.