Skip to content

createManagementExpressRouter

function createManagementExpressRouter<TContext>(options): Router;

Defined in: management-express/src/router.ts:71

Creates an Express router for the Monque Management Surface.

Mount the returned router in the host Express application at the path where operators should access management endpoints. Management API routes are served by the oRPC OpenAPI HTTP handler from @monque/management, so the Express adapter follows the same Management Route Map contract and response DTOs as other Management Adapters.

By default, the router also serves OpenAPI JSON at /openapi.json relative to the mount path. Disable that route with openApi: false, or configure its path and server URL with openApi.

Authentication belongs to the host Express app. Mount authentication middleware before this router, then use context and the framework-neutral authorize hook for action-grained Management Surface authorization.

Type ParameterDefault typeDescription
TContextunknownApplication-specific context exposed to management hooks.
ParameterTypeDescription
optionsManagementExpressRouterOptions<TContext>Monque Management Surface options plus Express adapter options.

Router

An Express router that can be mounted with app.use().

app.use(
	'/monque',
	createManagementExpressRouter({
		monque,
	}),
);
app.use(
	'/monque',
	requireOperator,
	createManagementExpressRouter<{ userId: string; role: string }>({
		monque,
		context: ({ req }) => ({
			userId: req.get('x-user-id') ?? 'anonymous',
			role: req.get('x-role') ?? 'viewer',
		}),
		authorize: ({ action, context }) => {
			return context.role === 'operator' || action === 'read';
		},
	}),
);
app.use(
	'/internal/management',
	createManagementExpressRouter({
		monque,
		openApi: {
			path: '/docs/openapi.json',
			serverUrl: 'https://ops.example.com/internal/management',
		},
	}),
);