Skip to content

cxRouter

Auto-generated documentation from JSDoc comments

Classes

Functions

cxRouter

Provides Request/Response bridge for running Hono routers inside the sandbox.

This module enables scripts to use Hono (or any router that follows the Web Standard Request/Response interface) by converting serialized request data into Web Request objects and serializing Response objects back to plain data.

Basic Usage

import { Hono } from 'hono'; // Auto Replaced

export const router = true;

const app = new Hono();

app.get('/', (c) => c.json({ message: 'Hello World' }));
app.get('/users/:id', (c) => c.json({ id: c.req.param('id') }));
app.post('/users', async (c) => {
  const body = await c.req.json();
  return c.json({ created: body }, 201);
});

export { app };

With Zod-OpenAPI

import { OpenAPIHono, createRoute, z } from 'esm.sh/@hono/zod-openapi';

export const router = true;

const app = new OpenAPIHono();

const getUserRoute = createRoute({
  method: 'get',
  path: '/users/{id}',
  auth: 'control-panel',
  request: {
    params: z.object({ id: z.string() }),
  },
  responses: {
    200: {
      content: {
        'application/json': {
          schema: z.object({ id: z.string(), name: z.string() }),
        },
      },
      description: 'User details',
    },
  },
});

app.openapi(getUserRoute, (c) => {
  return c.json({ id: c.req.param('id'), name: 'John Doe' });
});

// Auto-generate OpenAPI spec
app.doc('/openapi.json', {
  openapi: '3.1.0',
  info: { title: 'My API', version: '1.0.0' },
});

export { app };

Access your router at: GET /r/{scriptId}/users/123 OpenAPI spec at: GET /r/{scriptId}/openapi.json

Kind: global class

handleRequest(app, requestData, meta) ⇒ Promise.<Object>

Handle an incoming request with a Hono app

This is the main entry point called by the worker when processing router requests. Uses Hono's native fetch() method to properly execute middleware chains, then serializes the Response back to plain data for RPC transport.

Kind: global function
Returns: Promise.<Object> - Serialized response data

Param Type Description
app Object Hono app instance (must have fetch method)
requestData Object Serialized request data
meta Object Request metadata (correlationId, auth, etc.)