Skip to content

createRouter

function createRouter<Action, Resource, Ctx, Grant, Tag>(options): Router<Action, Resource, Ctx, Grant, Tag>;

Defined in: src/server/router.ts:168

Build a router from a route table.

Per request: match (collecting the methods a path supports, HEAD served by GET) → 405 + Allow if only the method is wrong → authenticate (routes with an action, or authenticate: true) → 401 / challenge → resource → authorize (scoped grants via scoped.allows, never the host provider) → 403 → readonly (readonlyStatus) → handler. Every thrown error goes through mapError with errors.

Type Parameter Default type
Action extends string -
Resource -
Ctx -
Grant never
Tag extends string string
Parameter Type
options RouterOptions<Action, Resource, Ctx, Grant, Tag>

Router<Action, Resource, Ctx, Grant, Tag>

const router = createRouter({
routes: ROUTES,
context: { core },
auth,
authorization,
isMutatingAction,
readonly,
readonlyStatus: 423,
errors: { NotFoundError: { status: 404, code: "NOT_FOUND" } },
});
createPanelHandler({ ..., api: router.handle });